Getting Microsoft Speech Agent to record WAV file

Blake81

Well-known member
Joined
Feb 23, 2006
Messages
304
Location
Georgia, USA
Programming Experience
1-3
This may be a little hard to understand, so I'll try to explain this the best I can. There is a program called Echolink for amateur radio operators that connects repeaters through the internet around the world. You can have Echolink running on your repeater or tied to your radio on a simplex link (just a frequency). The Echolink developers have made a help file available about the API so that you can write scripts and programs for it. I'm trying to write a program that will look up the weather for any zip code sent through the link by DTMF tones (basically punching numbers on the radio's keypad) and then speak the weather over the air. Echolink does not have the ability to recognize text and "read", so I want to use the Microsoft Speech Agent to read the string. I need it to save that to a WAV file that I can then play on the air. Does anyone know how to incorporate the speech agent into a VB app, and also how to get a WAV file of the agent "reading" a string? Thanks for any help.

Blake
 

JohnH

VB.NET Forum Moderator
Staff member
Joined
Dec 17, 2005
Messages
15,603
Location
Norway
Programming Experience
10+
See this thread about setting up the Speech library: http://www.vbdotnetforums.com/showthread.php?t=8638&highlight=text+speech

Here is the code to output the speech to wave file:
VB.NET:
[SIZE=2]
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] s [/SIZE][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] SpeechLib.SpVoice
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] fs [/SIZE][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] SpeechLib.SpFileStream
fs.Open([/SIZE][SIZE=2][COLOR=#800000]"test.wav"[/COLOR][/SIZE][SIZE=2], SpeechLib.SpeechStreamFileMode.SSFMCreateForWrite)
s.AudioOutputStream = fs
s.Voice = s.GetVoices.Item(0)
s.Speak([/SIZE][SIZE=2][COLOR=#800000]"Hello, this is a new voice."[/COLOR][/SIZE][SIZE=2])
[/SIZE]
 

Blake81

Well-known member
Joined
Feb 23, 2006
Messages
304
Location
Georgia, USA
Programming Experience
1-3
Thanks so much! It worked! Now, I just need to be picky about the format. The program that I'm interfacing with will not play WAV files unless they are 8 bit, 8000-Hz, PCM Mono. I saw that fs has a property called Format, and that there is an interface called SpeechLib.SpAudioFormat, but I'm not sure how to use it. How do you tell this to save the file in that format? It seems like it should be easy, but I don't know the syntax for using that interface. Thanks again.
 

JohnH

VB.NET Forum Moderator
Staff member
Joined
Dec 17, 2005
Messages
15,603
Location
Norway
Programming Experience
10+
This looks to be the reqested format, I would think you set it before opening the file. Have a look at all the other format options, there is a very long list.
VB.NET:
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] af [/SIZE][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] SpeechLib.SpAudioFormat[/SIZE]
[SIZE=2]af.Type = SpeechLib.SpeechAudioFormatType.SAFTADPCM_8kHzMono[/SIZE]
[SIZE=2]fs.Format = af[/SIZE]
 

Blake81

Well-known member
Joined
Feb 23, 2006
Messages
304
Location
Georgia, USA
Programming Experience
1-3
I got this figured out on my own, probably just as you were writing this. This is what I have:

VB.NET:
[SIZE=2][COLOR=#0000ff]Private[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] Button6_Click([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] sender [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.Object, [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] e [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.EventArgs) [/SIZE][SIZE=2][COLOR=#0000ff]Handles[/COLOR][/SIZE][SIZE=2] Button6.Click
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] fs [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] SpeechLib.SpFileStream
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] setformat [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] SpeechLib.SpAudioFormat
setformat.Type = SpeechLib.SpeechAudioFormatType.SAFT8kHz8BitMono
fs.Format.Type = setformat.Type
fs.Open([/SIZE][SIZE=2][COLOR=#800000]"C:\Documents and Settings\Owner\Desktop\test.wav"[/COLOR][/SIZE][SIZE=2], SpeechLib.SpeechStreamFileMode.SSFMCreateForWrite)
s.AudioOutputStream = fs
s.Voice = s.GetVoices.Item(0)
s.Speak([/SIZE][SIZE=2][COLOR=#800000]"Hello, this is another line of text."[/COLOR][/SIZE][SIZE=2])
fs.Close()
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]
[/COLOR][/SIZE]

Thanks :)
 

JohnH

VB.NET Forum Moderator
Staff member
Joined
Dec 17, 2005
Messages
15,603
Location
Norway
Programming Experience
10+
Yes, I just found that ADPCM and PCM is not the same, SAFT8kHz8BitMono reports as PCM format and should be right.
 

Blake81

Well-known member
Joined
Feb 23, 2006
Messages
304
Location
Georgia, USA
Programming Experience
1-3
Here's a WAV file of my program working:

http://blakenet.myftp.org/test.wav

Now I just have to wait for the sound card interface that I ordered to get here, and I can start working on parsing DTMF tones from the radio. I guess I'll need to look into how to get a substring out of a string. I'll have it so that you hit 9 on the keypad followed by the zip code to get the weather. I'll have to parse out the 9 to pass the zip code to the program. Thanks for your help.
 

Blake81

Well-known member
Joined
Feb 23, 2006
Messages
304
Location
Georgia, USA
Programming Experience
1-3
I got most of it working now. I didn't have to wait for my interface. I had forgotten that I could have Echolink running and just make sure that it was making the WAV file correctly. I still need to add the part about having Echolink play the file, but that should be just one line. I would like to figure out a way to have the speech agent say each number individually in a zip code. For example, the zip code "15905" is now being said as "Fifteen thousand nine hundred five". I'd like it to be "One five nine zero five". If there is an option to change this in the agen, that would be good, but I guess I could just parse out each number and give it that way. Here's the code for what I have so far, which is 99% of the program.

http://blakenet.myftp.org/echoweather.doc
 

JohnH

VB.NET Forum Moderator
Staff member
Joined
Dec 17, 2005
Messages
15,603
Location
Norway
Programming Experience
10+
You have to take the number string and replace it with one where you have put a space between each character. Then Speech will spell each digit.
 

Blake81

Well-known member
Joined
Feb 23, 2006
Messages
304
Location
Georgia, USA
Programming Experience
1-3
Thanks. I got that figured out today. It's been awhile since I've done anything with VB, but I have another problem that should be simple. I have a Handler for one of the events in Echolink, and basically, I'm trying to add an item to a listbox when that event fires. The confusing part is that every time the event fires, I can get a messagebox to show the data I want to add, but Listbox1.Items.Add does not add the item. Why would that be? Here's my code:

VB.NET:
[SIZE=2][COLOR=#0000ff]Private[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] echolink_Connected([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] callsign [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] Name [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] address [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][SIZE=2]) [/SIZE][SIZE=2][COLOR=#0000ff]Handles[/COLOR][/SIZE][SIZE=2] EchoLink.Connected
MessageBox.Show(callsign)
WhoConnect.Items.Add(callsign)
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]
[/COLOR][/SIZE]
 
Top Bottom