I need to turn a text into speech and then save it as wav file.
To use Speak: Select a word or block of text in your document. In the Quick Access Toolbar, select the Speak selected text icon.
Narrator reads aloud the text on your PC screen. It also describes events such as notifications and calendar appointments, which lets you use your PC without a display. To start or stop Narrator, press Windows logo key + Ctrl + Enter. To see all Narrator commands, press Caps Lock + F1 after you open Narrator.
1. To start Narrator press the Windows key + Ctrl + Enter on your keyboard. Narrator will read aloud items on the screen, including buttons and menus, as you select them or navigate through them using the keyboard. It will also read aloud any text that you select.
The following C# code uses the System.Speech namespace in the .Net framework. It is necessary to reference the namespace before using it, because it is not automatically referenced by Visual Studio.
SpeechSynthesizer ss = new SpeechSynthesizer();
ss.Volume = 100;
ss.SelectVoiceByHints(VoiceGender.Female, VoiceAge.Adult);
ss.SetOutputToWaveFile(@"C:\MyAudioFile.wav");
ss.Speak("Hello World");
I hope this is relevant and helpful.
This is from a few moments' play, so caveat emptor. Worked well for me. I did notice that SpFileStream (which doesn't implement IDisposable, thus the try/finally) prefers absolute paths to relative. C#.
SpFileStream fs = null;
try
{
SpVoice voice = new SpVoice();
fs = new SpFileStream();
fs.Open(@"c:\hello.wav", SpeechStreamFileMode.SSFMCreateForWrite, false);
voice.AudioOutputStream = fs;
voice.Speak("Hello world.", SpeechVoiceSpeakFlags.SVSFDefault);
}
finally
{
if (fs != null)
{
fs.Close();
}
}
And as I've found for how to change output format, we code something like this :
SpeechAudioFormatInfo info = new SpeechAudioFormatInfo(6, AudioBitsPerSample.Sixteen, AudioChannel.Mono);
//Same code comes here
ss.SetOutputToWaveFile(@"C:\MyAudioFile.wav",info);
That's pretty easy and comprehensible.
Cool .net
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With