i try to save a audio from mobile microphone to a Tmemorystream and then convert it to hex with this function:
function StreamToHexStr(AStream: TStream): string;
HexArr: array[0..15] of char =
SetLength(Result, AStream.Size * 2);
AStream.Position := 0;
for i := 0 to AStream.Size – 1 do
Result[i * 2 + 1] := HexArr[AByte shr 4];
Result[i * 2 + 2] := HexArr[AByte and $0F];
the output is a hexadecimal string
after transfer it a a second device i have to change the hex code to a Tmemorystream and the play it with this function:
Stream := TMemoryStream.Create;
Writer := TBinaryWriter.Create(Stream);
Stream.SaveToFile( TPath.GetSharedMoviesPath()+’/record2.mp3′ );
but the record2.mp3 is not playable and it just include the converted hex string
what is wrong with my code?
for a simple test when i save the recorded stream to a file with this code
FOutputStream.SaveToFile( TPath.GetSharedMoviesPath()+’/record.mp3′ );
it working good.
update project concept:
the hardware transmitter get 406 hex char from mobile phone on serial port and transfer it to second device,then the receiver deliver the hex string to second mobile phone , the second phone must join the strings and convert them to a hear-able sound.
a sample output of base64 to stream and stream save to file
sample mp3 file