我一直想做的一周以上是通过语音识别在网络上启用自定义搜索。我想要的是这样当我说网络搜索时,我的程序会添加识别的语音并附加一个字符串,然后我可以将其添加到网址的末尾以便搜索网页
这是当前代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Speech.Recognition;
using System.Speech.Synthesis;
namespace AID
{
public partial class Form1 : Form
{
SpeechSynthesizer s = new SpeechSynthesizer();
SpeechRecognitionEngine reg = new SpeechRecognitionEngine();
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
string test = "12345".ToString().Replace("123", "");
s.Speak("booting up");
s.Speak("AID online");
s.Speak("Hello sir, how may i assist you?");
string[] commands = { "hello AID", "what are you", "how are you", "what's the time", "open music", "sing me a song", "thank you AID", "what does AID mean", "Tell me a joke", "i need to take notes", "i want to search the web"
,"i want to check my mail","run lol","the yogscast","calabrate voice","where are you","tell me the truth","aid wakeup","aid exit","Who is bad"};
reg.SetInputToDefaultAudioDevice();
reg.LoadGrammar(new Grammar(new GrammarBuilder(new Choices(commands))));
reg.RecognizeAsync(RecognizeMode.Multiple);
reg.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(rec);
}
public string time()
{
DateTime n = DateTime.Now;
string o = n.GetDateTimeFormats('t')[0];
return o;
}
public void rec(object sender, SpeechRecognizedEventArgs x)
{
string recString = x.Result.Text;
switch(recString)
{
case "hello AID":
s.Speak("Hello sir");
break;
case "how are you":
s.Speak("I'm good, how are you?");
break;
case "what's the time":
s.Speak(time());
break;
case "open music":
s.Speak("on it sir");
System.Diagnostics.Process.Start("wmplayer.exe");
break;
case "sing me a song":
s.Speak("im a little tea pot short and stout here is my handle here is my spout if you poor me over hear me shout tip me up and poor me out");
break;
case "thank you AID":
s.Speak("you are very welcome sir ");
break;
case "what are you":
s.Speak("I am AID");
break;
case "what does AID mean":
s.Speak("Aid means assistance and intelligent device");
break;
case "Tell me a joke":
s.Speak("I like my relationships like I like my source, open");
break;
case "i need to take notes":
s.Speak("opening notepad now sir");
System.Diagnostics.Process.Start("notepad.exe");
break;
case "i want to search the web":
s.Speak("What do you wish to search sir");
System.Diagnostics.Process.Start("https://www.google.co.uk/search?q=" );
break;
case "i want to check my mail":
s.Speak("opening your inbox now sir");
System.Diagnostics.Process.Start("https://mail.google.com/mail/u/0/#inbox");
break;
case "run lol":
s.Speak("opening league of legends now sir");
System.Diagnostics.Process.Start(@"C:\Riot Games\League of Legends\lol.launcher.exe");
break;
case "the yogscast":
s.Speak("opening the yogscast youtube channel now sir");
System.Diagnostics.Process.Start("https://www.youtube.com/user/BlueXephos");
break;
case "calabrate voice":
s.Speak("voice calabration complete");
break;
case "where are you":
s.Speak("Im here");
break;
case "tell me the truth":
s.Speak("the truth is all but lies ");
break;
case "aid wakeup":
s.Speak("Awake and awaiting further instruction sir");
break;
}
}
}
}
答案 0 :(得分:1)
在您的应用程序中开发文本到语音或语音识别并不容易。不久前,微软在Build会议上提出Project Oxford,可以同时做这两件事。
在Live Demo中试用。
它使用REST API,因此您需要Internet访问才能使用此服务。对于文本转语音,您基本上将文本发送到该服务,然后下载您刚刚播放的声音文件。对于语音识别,它是另一种方式,您发送音频文件并接收识别的文本。
我没有这方面的经验,但我相信您可以在documentation找到所需的所有信息。