0

インストールされている男性、女性などの声をC#プログラムで使いたいです。私はスピーチシンセサイザーとspeakAsync関数を使用しています。私を助けてください。

4

3 に答える 3

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);

これにより、インストールされているすべてのボイスがリストに入れられ、リストの最初のボイスが選択されたボイスとして使用されます。

于 2011-05-08T06:34:50.147 に答える
1

あなたのプログラムが話すようにしたい場合は、これを使ってみてください:

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

そして、この関数を次のように呼び出します。Say("Hello World"!);

以下を必ず含めてください。using System.Speech.Synthesis;

于 2011-05-08T06:38:04.603 に答える
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?");
        }
    }
于 2011-05-08T07:25:02.180 に答える