2011-05-08 113 views
0

我想在c#程序中使用男聲,女聲等。我使用speechsynthesizer ans speakAsync功能。請幫幫我。如何在c#visual studio 2010中使用已安裝的聲音

+1

你有什麼問題?你能發佈你的代碼嗎? – Oded 2011-05-08 06:28:57

+0

@Oded我實際上不知道如何使用安裝的聲音。 – Deepak 2011-05-08 06:30:57

+0

沒有足夠的針對性,也沒有顯示足夠的背景準備,以便在stackoverflow上可以接受。 – 2011-05-08 06:33:50

回答

3

這裏是如何在你的應用程序中實現語音的簡單的文章:

http://www.dotnetfunda.com/articles/article828-build-your-talking-application-.aspx

正如文章的一部分,它顯示瞭如何列出所有已安裝的聲音,它也展示瞭如何然後在您的應用程序中使用您選擇的語音。下面是示例代碼本文爲:

List lst = new List(); 
foreach (InstalledVoice voice in spsynthesizer.GetInstalledVoices()) 
{ 

    lst.Items.Add(voice.VoiceInfo); 
} 

spsynthesizer.SelectVoice(lstVoice[0].Name); 

這將使所有已安裝的聲音轉爲列表,它會使用第一個聲音在列表中選擇聲音。

1

如果你想要找你的程序發言試用以下:

public void Say(string say) 
{ 
    SpeechSynthesizer talker = new SpeechSynthesizer(); 
    talker.Speak(say); 
} 

而且這樣調用這個函數:Say("Hello World"!);

請確保您有:using System.Speech.Synthesis;

0

如果您需要得到一個男性或女性的聲音清單,你可以做這樣的事情:

private static void Main() 
    { 
     Speak(VoiceGender.Male); 
     Speak(VoiceGender.Female); 
    } 

    private static void Speak(VoiceGender voiceGender) 
    { 
     using (var speechSynthesizer = new SpeechSynthesizer()) 
     { 
      var genderVoices = speechSynthesizer.GetInstalledVoices().Where(arg => arg.VoiceInfo.Gender == voiceGender).ToList(); 
      var firstVoice = genderVoices.FirstOrDefault(); 
      if (firstVoice == null) 
       return; 
      speechSynthesizer.SelectVoice(firstVoice.VoiceInfo.Name); 
      speechSynthesizer.Speak("How are you today?"); 
     } 
    } 
相關問題