문제

I have a problem. I have a RichTextBox, and I want convert text to speech audio, so is there some library or program to do this ? I want do this in C#, WinForms.

Update:

private void aiutoVocaleToolStripMenuItem_Click(object sender, EventArgs e)
{
    string contenuto_valore = TextBox_stampa_contenuto.Text.Trim();
    var s = new System.Speech.Synthesis.SpeechSynthesizer();
    s.Speak(contenuto_valore);
}

the program says that there are not reference to assembly

도움이 되었습니까?

해결책

You could use the MS TTS:

http://msdn.microsoft.com/de-de/library/system.speech.synthesis.speechsynthesizer%28v=vs.110%29.aspx

Use TTS:

private static SpeechSynthesizer speaker;

public static void Main(String[] args){
  speaker = new SpeechSynthesizer();
  speaker.SetOutputToDefaultAudioDevice();
  speaker.Rate = 1;
  speaker.Volume = 100;
  speaker.SelectVoiceByHints(VoiceGender.Female, VoiceAge.Adult);
  speaker.SpeakAsync("Hello World"); 
}

private static List<VoiceInfo> GetInstalledVoices() {
  var listOfVoiceInfo = from voice
                        in  speaker.GetInstalledVoices()
                        select voice.VoiceInfo;

  return listOfVoiceInfo.ToList<VoiceInfo>();
}

Just read the RichTextBox's Text property to get the Text

다른 팁

Built-in to .NET

var s = new System.Speech.Synthesis.SpeechSynthesizer();
s.Speak("hello");

http://msdn.microsoft.com/en-us/library/ms586901(v=vs.110).aspx

Read the RichTextBox value (split it if it's very large text) and make a request to translate.google.com as:

http://translate.google.com/translate_tts?tl=en&q=Your%20Text%20Here

You can obtain the sound file generated using HTTP GET, if you must. Remeber, your client will need to have access to internet


You'll need to reference System.Speech.dll in order to use SpeechSynthesizer(). Follow there steps:

  1. Locate and right click References in Solution Explorer
  2. Click Add option from the context menu
  3. Reference Manager pop-up will show, In Assemblies - Framework try to locate System.Speech.dll
  4. If you can find, check it and click OK

Now you can run the following code;

private void aiutoVocaleToolStripMenuItem_Click(object sender, EventArgs e)
{
    using (SpeechSynthesizer synth = new SpeechSynthesizer())
    {        
        synth.SetOutputToDefaultAudioDevice();

        synth.Speak(TextBox_stampa_contenuto.Text.Trim());
    }
} 
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top