C# 重复文本到语音合成

C# repeating text to speech synthesis

提问人:PKYNI 提问时间:11/24/2020 更新时间:11/26/2020 访问量:300

问:

因此,我正在尝试编写一个文本转语音程序,该程序会逐渐变得更快,句子之间的间隙会更小,最终会同时分层和运行多个命令,因此它变得一团糟。它目前是一个控制台应用程序,我包含相关参考资料

任何想法我如何调整它以将每个说话命令作为其自己的实例运行。我是否必须重新学习如何多线程才能让它工作?

任何帮助都会很棒,在它循环的那一刻(迭代次数不是太重要),我试图在每次迭代后减少停顿,但无法获得一个说话命令来覆盖上一个。

for (int i = 0; i < 100; i++)
            {
                if (Console.KeyAvailable == true)
                {
                    break;
                }
                else
                {
                    if (i == 0)
                    {
                        string commandLine2 = "Hello darkness my old friend";
                        SpeechSynthesizer s = new SpeechSynthesizer();
                        s.SelectVoiceByHints(VoiceGender.Female, VoiceAge.Child);
                        s.Speak(commandLine2);
                        commandLine2 = "Its been a while where should we begin";
                        //Thread.Sleep(1000);
                        s.Speak(commandLine2);
                    }
                    else
                    {
                        string commandLine2 = "Hello darkness my old friend";
                    SpeechSynthesizer s = new SpeechSynthesizer();
                    s.SelectVoiceByHints(VoiceGender.Female, VoiceAge.Child);
                    s.Speak(commandLine2);
                    commandLine2 = "Its been a while where should we begin";
                    //Thread.Sleep(1000 / i);
                    s.Speak(commandLine2);
                }

            }
        }
C# 文本转 语音合成

评论

0赞 Evk 11/24/2020
所以重叠是目标,还是你想要修复的错误?它现在的行为如何,在相等的间隔内说话?
0赞 StayOnTarget 11/24/2020
您是否正在使用 learn.microsoft.com/en-us/dotnet/api/...
0赞 PKYNI 11/25/2020
过圈是目标,目前它只是在一句话说完后才说话,但想引起重叠。是的,使用那个类,不知道任何其他类

答:

1赞 PKYNI 11/26/2020 #1

我最后只是使用了多线程。这一切都涌向我

 for (int i = 1; i < 100; i++)
        {
            Thread t1 = new Thread(mySpeach);
            t1.Name = "Thread1";
            t1.Start();
            Thread.Sleep(2000 / i);
            if (Console.KeyAvailable == true)
            {
                t1.Abort();
                break;
            }
        }

//other methods were here


    public static void typing()
        {
        string a = "Hello darkness my old friend\nIts been a while where should we begin";
        for (int i = 0; i < a.Length; i++)
        {
            Random rnd = new Random();
            Console.Write(a[i]);
            if (Console.KeyAvailable == true)
            {
                break;
            }
            Thread.Sleep(rnd.Next(50, 100));
        }
        Console.WriteLine("");
    }

    public static void mySpeach()
    {
        string commandLine2 = "Hello darkness my old friend";
        Thread t2 = new Thread(typing);

        t2.Name = "Thread2";

        t2.Start();
        SpeechSynthesizer s = new SpeechSynthesizer();
        s.SelectVoiceByHints(VoiceGender.Female, VoiceAge.Child);
        s.Speak(commandLine2);
        commandLine2 = "Its been a while where should we begin";
        if (Console.KeyAvailable == true)
        {
            return;
        }
        s.Speak(commandLine2);
        Thread.Sleep(1000);
    }