sasabistrovic
asked on
Convert WAV to TEXT
Convert WAV to TEXT
How to convert WAV to TEXT and play sound from text ?
For example : convert from Wave to Memo.Text and play it from Memo.Text
Thanks.
How to convert WAV to TEXT and play sound from text ?
For example : convert from Wave to Memo.Text and play it from Memo.Text
Thanks.
How exactly do you want to convert WAV to TEXT? Do you mean spoken words into Text then when you press play turn the words back into speech?
Or do you mean take the RAW binary data that makes up the WAV format and place that into the Text? It won't be readable.
I think you need to post more information about what you're trying to accomplish.
Or do you mean take the RAW binary data that makes up the WAV format and place that into the Text? It won't be readable.
I think you need to post more information about what you're trying to accomplish.
ASKER
No, I didn't mean Text-To-Speech.
Yes, something like taking RAW binary data that makes up the WAV format and place that into the Text.
Thanks.
Sorry, I'm beginner in that.
Yes, something like taking RAW binary data that makes up the WAV format and place that into the Text.
Thanks.
Sorry, I'm beginner in that.
This can easily be done with the following function
function ConvertRawFileToText( FileName: string ): string;
var
Q: integer;
StringStream: TStringStream;
MemoryStream: TMemoryStream;
str: string;
begin
MemoryStream :=TMemoryStream.Create;
StringStream :=TStringStream.Create('') ;
MemoryStream.LoadFromFile( FileName);
StringStream.CopyFrom(Memo ryStream, 0);
result :=FastReplace( StringStream.DataString, #0, #1 );
StringStream.Free;
MemoryStream.Clear;
MemoryStream.Free;
end;
The call to FastReplace requires you to include in uses the unit FastStrings.
This can be downloaded from http://www.swissdelphicenter.ch/torry/showcode.php?id=1857
The trick is that you must replace the #0 (null) characters by something else. I chose #1.
Evarest
function ConvertRawFileToText( FileName: string ): string;
var
Q: integer;
StringStream: TStringStream;
MemoryStream: TMemoryStream;
str: string;
begin
MemoryStream :=TMemoryStream.Create;
StringStream :=TStringStream.Create('')
MemoryStream.LoadFromFile(
StringStream.CopyFrom(Memo
result :=FastReplace( StringStream.DataString, #0, #1 );
StringStream.Free;
MemoryStream.Clear;
MemoryStream.Free;
end;
The call to FastReplace requires you to include in uses the unit FastStrings.
This can be downloaded from http://www.swissdelphicenter.ch/torry/showcode.php?id=1857
The trick is that you must replace the #0 (null) characters by something else. I chose #1.
Evarest
And of course, use it as follows:
procedure TForm1.Button1Click(Sender : TObject);
begin
RichEdit1.Text :=ConvertRawFileToText('C: \WINDOWS\M edia\ringi n.wav');
end;
Evarest
procedure TForm1.Button1Click(Sender
begin
RichEdit1.Text :=ConvertRawFileToText('C:
end;
Evarest
If you want to play the sound directly from that Text, you'll need to remember which characters you've replaced... Then it's best to use another method to replace the characters and save the positions in some sort of List.
I can't understand however why you'd like to play from a memo, as you have the WAV on your system. You can play it by calling
var
aFile: string;
begin
aFile :='C:\WINDOWS\Media\ringin .wav';
sndPlaySound(pChar(aFile), snd_Async or snd_NoDefault);
end;
and include MMSystem in the uses of your unit.
Evarest
I can't understand however why you'd like to play from a memo, as you have the WAV on your system. You can play it by calling
var
aFile: string;
begin
aFile :='C:\WINDOWS\Media\ringin
sndPlaySound(pChar(aFile),
end;
and include MMSystem in the uses of your unit.
Evarest
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
"Which is not really a good idea, as there's a legitimate reason for #0's in this string,"
Indeed, but the initial question was a text representation of the WAV file. This can only be done if you replace all occurencies of #0 by some other representable character.
Evarest
Indeed, but the initial question was a text representation of the WAV file. This can only be done if you replace all occurencies of #0 by some other representable character.
Evarest
Or alternatively encodeing the entire binary file in such a way that you can decode it back into it's original form.
Before I forget, in Win9x the TMemo is limited to 64KB of text MAX. It's 2GB for Win2000/xp. You need to becareful that you don't overrun the memo component with data.
Before I forget, in Win9x the TMemo is limited to 64KB of text MAX. It's 2GB for Win2000/xp. You need to becareful that you don't overrun the memo component with data.
"Before I forget, in Win9x the TMemo is limited to 64KB of text MAX. It's 2GB for Win2000/xp. You need to becareful that you don't overrun the memo component with data."
That's why i used a TRichEdit :-) However, loading really large files into a textbox can be quite (very) slow. Some optimization may then be needed...
That's why i used a TRichEdit :-) However, loading really large files into a textbox can be quite (very) slow. Some optimization may then be needed...
ASKER
Well thanks.
How to ConvertTextToRawFile (to encode stream) to play wav sound ?
How to ConvertTextToRawFile (to encode stream) to play wav sound ?
ASKER
I tried to encode wav file and than to decode.
Can I (after encoding file) add something to (modify) wav file ?
procedure TForm1.Button3Click(Sender : TObject);
begin
MimeEncodeFile('C:\WINDOWS \Media\rin gin.wav',' C:\WINDOWS \Media\rin gin_hex.tx t');
end;
procedure TForm1.Button4Click(Sender : TObject);
begin
MimeDecodeFile('C:\WINDOWS \Media\rin gin_hex.tx t','C:\WIN DOWS\Media \ringin2.w av');
end;
Can I (after encoding file) add something to (modify) wav file ?
procedure TForm1.Button3Click(Sender
begin
MimeEncodeFile('C:\WINDOWS
end;
procedure TForm1.Button4Click(Sender
begin
MimeDecodeFile('C:\WINDOWS
end;
I should have guessed that was comming. In order to modify a WAV file, you need to work with it in it's encoded form. You need to manipluate the data to that it remains compaible with the WAV format. You'll find details of it here...
http://www.borg.com/~jglatt/tech/wave.htm
if that's no good do a GOOGLE lookup for WAV Format specification That should get you on the right track.
http://www.borg.com/~jglatt/tech/wave.htm
if that's no good do a GOOGLE lookup for WAV Format specification That should get you on the right track.
ASKER
So, Wav file is structured from chunks :
Format Chunk,
Data Chunk,
Cue Chank,
Playlist Chunk,
Associated Data List,
Sampler Chunk and
Instrument Chunk.
How to extract them from Wav file and modify them ?
I read that in Wav file are sample points that are meant to be "played" simultaneously are collectively called a sample frame ?
So there are in Sampler Chunk ?
How to modify them to get a new sound ?
Thanks.
Format Chunk,
Data Chunk,
Cue Chank,
Playlist Chunk,
Associated Data List,
Sampler Chunk and
Instrument Chunk.
How to extract them from Wav file and modify them ?
I read that in Wav file are sample points that are meant to be "played" simultaneously are collectively called a sample frame ?
So there are in Sampler Chunk ?
How to modify them to get a new sound ?
Thanks.
Now you're asking a completely different question from the one that you originally asked.
ASKER
Because I open (hex) and save back Wav file with Colin Dawson comment I'll give all experts points to him.
Thanks.
Thanks.
Thanks for the points.
I'm sure if you start a new question there are experts that will knowledgable about the inner workings of the wav format.
I'm sure if you start a new question there are experts that will knowledgable about the inner workings of the wav format.
myControl.Speak('The text here'); or myControl.Speak(Memo1.Text
use the Component Menu | Import ActiveX control, you'll see those (Microsoft) names listed