[英]C# repeating text to speech synthesis
So I am trying to write a text to speech program that will progressively get faster, leaving less of a gap between sentences and eventually over layering and running multiple of the commands at the same time so it becomes just a mess of noise.所以我正在尝试编写一个文本转语音程序,它会逐渐变快,在句子之间留下更少的间隙,并最终在同一时间对多个命令进行分层和运行,因此它只是一团糟。 Its currently a console application and I have the relevant references included
它目前是一个控制台应用程序,我有相关的参考资料
Any ideas how I adapt this to run each speak command as its own instance.我如何调整它以将每个说话命令作为自己的实例运行的任何想法。 Would I have to re-learn how to multithread to get it to work?
我是否必须重新学习如何多线程才能使其工作?
Any help would be great, at the minute it loops (the number of iterations is not too important) and I have tried to get less of a pause after each one but cannot get one speak command to layer over the pervious.任何帮助都会很棒,在它循环的那一刻(迭代次数不是太重要),我试图在每次停顿之后减少停顿,但无法获得一个说话命令来覆盖之前的内容。
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);
}
}
}
I just used multithreading in the end.最后我只是使用了多线程。 It all came rushing back to me
这一切都冲回到我身边
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);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.