Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Convert WAV to TEXT

Posted on 2004-09-03
17
Medium Priority
?
1,265 Views
Last Modified: 2012-05-05
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.
0
Comment
Question by:sasabistrovic
  • 6
  • 5
  • 5
  • +1
17 Comments
 
LVL 13

Expert Comment

by:BlackTigerX
ID: 11976235
you can add the "Microsoft Speech Recognition" and "Microsoft Direct Text-To-Speech" Activex Controls, I have used the Microsoft Text-To-Speech control, and all you have to do besides dropping the component on the form, is call it something like
myControl.Speak('The text here'); or myControl.Speak(Memo1.Text);

use the Component Menu | Import ActiveX control, you'll see those (Microsoft) names listed
0
 
LVL 4

Expert Comment

by:Colin_Dawson
ID: 11976241
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.
0
 

Author Comment

by:sasabistrovic
ID: 11976507
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.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 4

Expert Comment

by:Evarest
ID: 11976754
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(MemoryStream, 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
0
 
LVL 4

Expert Comment

by:Evarest
ID: 11976774
And of course, use it as follows:

procedure TForm1.Button1Click(Sender: TObject);
begin
 RichEdit1.Text :=ConvertRawFileToText('C:\WINDOWS\Media\ringin.wav');
end;

Evarest
0
 
LVL 4

Expert Comment

by:Evarest
ID: 11976801
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
0
 
LVL 4

Accepted Solution

by:
Colin_Dawson earned 1600 total points
ID: 11977747
Taking things a step further, instead of FastReplace( StringStream.DataString, #0, #1 );  Which is not really a good idea, as there's a legitimate reason for #0's in this string, you should cycle through the sound file and convert each Byte into it's hex representation.   Before you play the sound you'll need to convert it back.  Another alternative would be to BASE64 encode the stream.  (probably quicker)

you can find components that do the Base64 encode and decode for you at torry.net

Here's a link...  http://www.torry.net/pages.php?id=210   DIMime works pretty well.
0
 
LVL 4

Expert Comment

by:Evarest
ID: 11977903
"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
0
 
LVL 4

Expert Comment

by:Colin_Dawson
ID: 11977929
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.
0
 
LVL 4

Expert Comment

by:Evarest
ID: 11978002
"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...
0
 

Author Comment

by:sasabistrovic
ID: 11978058
Well thanks.

How to ConvertTextToRawFile (to encode stream) to play wav sound ?
0
 

Author Comment

by:sasabistrovic
ID: 11979164
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\ringin.wav','C:\WINDOWS\Media\ringin_hex.txt');
end;

procedure TForm1.Button4Click(Sender: TObject);
begin
MimeDecodeFile('C:\WINDOWS\Media\ringin_hex.txt','C:\WINDOWS\Media\ringin2.wav');
end;
0
 
LVL 4

Expert Comment

by:Colin_Dawson
ID: 11979499
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.
0
 

Author Comment

by:sasabistrovic
ID: 11980405
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.
0
 
LVL 4

Expert Comment

by:Colin_Dawson
ID: 11980527
Now you're asking a completely different question from the one that you originally asked.
0
 

Author Comment

by:sasabistrovic
ID: 11980693
Because I open (hex) and save back Wav file with Colin Dawson comment I'll give all experts points to him.

Thanks.
0
 
LVL 4

Expert Comment

by:Colin_Dawson
ID: 11980753
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.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question