c# - Speech recognition adding recognized speach to a string -
hi ive been trying on week enable custom searches on web via use of speech recognition. want when speak web search program add recognized speech , append string can add end of url in order search web
any appreciated
here current code
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 assist you?"); string[] commands = { "hello aid", "what you", "how you", "what's time", "open music", "sing me song", "thank aid", "what aid mean", "tell me joke", "i need take notes", "i want search web" ,"i want check mail","run lol","the yogscast","calabrate voice","where you","tell me truth","aid wakeup","aid exit","who 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 you": s.speak("i'm good, how you?"); break; case "what's time": s.speak(time()); break; case "open music": s.speak("on sir"); system.diagnostics.process.start("wmplayer.exe"); break; case "sing me song": s.speak("im little tea pot short , stout here handle here spout if poor me on hear me shout tip me , poor me out"); break; case "thank aid": s.speak("you welcome sir "); break; case "what you": s.speak("i aid"); break; case "what aid mean": s.speak("aid means assistance , intelligent device"); break; case "tell me joke": s.speak("i relationships like source, open"); break; case "i need take notes": s.speak("opening notepad sir"); system.diagnostics.process.start("notepad.exe"); break; case "i want search web": s.speak("what wish search sir"); system.diagnostics.process.start("https://www.google.co.uk/search?q=" ); break; case "i want check mail": s.speak("opening inbox sir"); system.diagnostics.process.start("https://mail.google.com/mail/u/0/#inbox"); break; case "run lol": s.speak("opening league of legends sir"); system.diagnostics.process.start(@"c:\riot games\league of legends\lol.launcher.exe"); break; case "the yogscast": s.speak("opening yogscast youtube channel sir"); system.diagnostics.process.start("https://www.youtube.com/user/bluexephos"); break; case "calabrate voice": s.speak("voice calabration complete"); break; case "where you": s.speak("im here"); break; case "tell me truth": s.speak("the truth lies "); break; case "aid wakeup": s.speak("awake , awaiting further instruction sir"); break; } } } }
it's not easy develop text-to-speech or voice recognition in application. not long ago, microsoft presented project oxford on build conference can both things.
try in live demo.
it uses rest api need internet access use service. text-to-speech send text service , download sound file you'll play. voice recognition, it's other way around, send audio file , receive recognized text.
i don't have experience this, believe can find information need in documentation.
Comments
Post a Comment