使用语音识别播放随机wav文件 [英] play random wav file using voice recognition

查看:161
本文介绍了使用语音识别播放随机wav文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我拥有所需的所有语音项目,因为项目将使用语音命令运行并以应有的方式响应。这是代码的一小部分。当我把它分配给表格上的一个按钮时,它会播放一个ramdom wav,它们最多只有10秒钟。我想移动到当我说其中一个关键词时它会像按下按钮时一样响应。我想我需要一行代码,但无法理解。





我正在处理语音请求程序当我说一个关键词时,我正试图让它播放一个随机的.wav文件。这是我到目前为止所做的,如果你按下表格上的一个按钮,它确实有效但我希望它在听到其中一个单词时播放。但无法获得最后的平安,任何帮助都会很棒。还在学习:





  case    for
case help
case now
string [] files = Directory.GetFiles( @ C:\ Users\chuck\voice< /跨度>);
Random rnd = new Random(Guid.NewGuid()。GetHashCode());
int choice = rnd.Next( 0 ,files.Length - 1 );
string soundFile = files [choice];
System.Media.SoundPlayer player = new System.Media.SoundPlayer(soundFile);
player.Play();







我在C#

解决方案

您可以使用 System.Speech.Recognition

http://msdn.microsoft.com/en-us/library/system .speech.recognition%28v = vs.110%29.aspx [ ^ ]。



替代方案是: SpeechRecognizer SpeechRecognitionEngine

http://msdn.microsoft.com/en-us/library/system.speech.recognition.speechrecognizer(v = VS。 110).aspx [ ^ ],

http://msdn.microsoft.com/en-us/library/system.speech.recognition.speechrecognitionengine(v = vs.110).aspx [ ^ ] 。



第一个请求STA线程公寓状态,第二个请求MTA。因此,如果您使用需要STA的WPF,您可以在单独的MTA线程中使用 SpeechRecognitionEngine ;和其他应用程序类型可以使用主线程中的任何公寓状态。这是通常的困难,因为微软没有正确记录这种微妙之处;其他一切或多或少都是直截了当的。而且,对于大语法集的识别质量是非常值得怀疑的,但只需要一些命令就足以让它变得可行。



-SA

i have all speech items needed as the project will run with voice commands and respond the way it should. this is a small piece of the code. when i had this assigned to a button on the form it would play one ramdom wav, they are only about 10 seconds long at the most. i want to move to when i say one of the key words it will respond the same as when you push the button. i think i need one line of code but can't figure it out.


I'm working on a speech req program and I'm trying to get it to play a random .wav file when i say a key word. this is what i have so far and it does work if you push a button on the form but i want it to play when it hears one of the words spoken. but can't get the last peace, any help would be great. still learning:


case "for":
case "help":
case"now":
    string[] files = Directory.GetFiles(@"C:\Users\chuck\voice");
    Random rnd = new Random(Guid.NewGuid().GetHashCode());
    int choice = rnd.Next(0, files.Length - 1);
    string soundFile = files[choice];
    System.Media.SoundPlayer player = new System.Media.SoundPlayer(soundFile);
    player.Play();




I'm doing this in C#

解决方案

You can use System.Speech.Recognition:
http://msdn.microsoft.com/en-us/library/system.speech.recognition%28v=vs.110%29.aspx[^].

The alternatives are: SpeechRecognizer or SpeechRecognitionEngine:
http://msdn.microsoft.com/en-us/library/system.speech.recognition.speechrecognizer(v=vs.110).aspx[^],
http://msdn.microsoft.com/en-us/library/system.speech.recognition.speechrecognitionengine(v=vs.110).aspx[^].

First one requites STA thread apartment state, and second one MTA. So, if you use WPF which requires STA, you can work SpeechRecognitionEngine in a separate thread set to MTA; and other application types could use any apartment state in the main threads. This is the usual difficulty, because this subtlety is not documented by Microsoft properly; everything else is more or less straightforward. And, well… quality of recognition of big grammar sets is quite questionable, but with just a set of few commands it's good enough to make it doable.

—SA


这篇关于使用语音识别播放随机wav文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆