Click here to Skip to main content
15,881,872 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
Hello guys,i have a question...How can i search something when i say "search for" + the thing i wanna search (via speech),(maybe in google?).Please help me,i am completly stuck :P,look my code so far...
C#
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;
using System.IO;

namespace JARVIStest
{
    public partial class Form1 : Form
    {
        SpeechRecognitionEngine _recognizer = new SpeechRecognitionEngine();
        SpeechSynthesizer JARVIS = new SpeechSynthesizer();
        string QEvent;
        int count = 1;
        Random rnd = new Random();

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            _recognizer.SetInputToDefaultAudioDevice();
            _recognizer.LoadGrammar(new Grammar(new GrammarBuilder(new Choices(File.ReadAllLines(@"C:\Users\Cpyros\Desktop\lefteris\Commands.txt")))));
            _recognizer.SpeechRecognized += new EventHandler<speechrecognizedeventargs>(_recognizer_SpeechRecognized);
            _recognizer.RecognizeAsync(RecognizeMode.Multiple);
        }
        void _recognizer_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
        {
            int ranNum = rnd.Next(1, 10);
            string speech = e.Result.Text;
            switch (speech)
            {
                //GREETINGS
                case "hello":
                case "hello jarvis":
                    if (ranNum < 6) { JARVIS.Speak("Hello sir"); }
                    else if (ranNum > 5) { JARVIS.Speak("Hi"); }
                    break;
                case "goodbye":
                case "goodbye jarvis":
                case "close":
                case "close jarvis":
                    JARVIS.Speak("Until next time");
                    Close();
                    break;
                case "jarvis":
                    if (ranNum < 5) { QEvent = ""; JARVIS.Speak("Yes sir"); }
                    else if (ranNum > 4) { QEvent = ""; JARVIS.Speak("Yes?"); }
                    break;

here i wanna add a case "search for" or "search google"
Posted
Updated 28-Aug-13 18:20pm
v2
Comments
BillWoodruff 28-Aug-13 20:00pm    
"maybe in Google" Have you done a thorough review of the current features of Google Voice Search, and information provided by Google on its speech-to-search API (if any), and the several 3rd. party extensions for Google that permit launching Google Voice Search outside Chrome ? You need to your homework.
Sergey Alexandrovich Kryukov 28-Aug-13 22:24pm    
First of all, it's hard to expect good results from such a bad programming style, where you try to hard-coded phrases, and so on, for such a complex project. And this code is almost irrelevant. Where are you trying to make an HTTP request for search and send it to Google?
—SA

1 solution

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900