Visualizzazione dei risultati da 1 a 6 su 6

Visualizzazione discussione

  1. #1

    [c#] Speech Recognition

    codice:
    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.Synthesis;
    using System.Speech.Recognition;
    using System.Threading;
    
    
    namespace Speaker
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
            SpeechSynthesizer sSynth = new SpeechSynthesizer();
            PromptBuilder pBuilder = new PromptBuilder();
            SpeechRecognitionEngine sRecognize = new SpeechRecognitionEngine();
            private void Form1_Load(object sender, EventArgs e)
            {
    
    
            }
    
    
            private void button1_Click(object sender, EventArgs e)
            {
                pBuilder.ClearContent();
                pBuilder.AppendText(textBox1.Text);
                sSynth.Speak(pBuilder);
            }
    
    
            private void button2_Click(object sender, EventArgs e)
            {
                button2.Enabled = false;
                button3.Enabled = true;
                Choices sList = new Choices();
                sList.Add(new string[] { "hello", "test", "it works", "how", "are", "you", "today", "i", "am", "fine", "exit", "close", "quit", "so" });
                Grammar gr = new Grammar(new GrammarBuilder(sList));
                try
                {
                    sRecognize.RequestRecognizerUpdate();
                    sRecognize.LoadGrammar(gr);
                    sRecognize.SpeechRecognized += sRecognize_SpeechRecognized;
                    sRecognize.SetInputToDefaultAudioDevice();
                    sRecognize.RecognizeAsync(RecognizeMode.Multiple);
                    sRecognize.Recognize();
    
    
    
    
                }
    
    
                catch
                {
                    return;
                }
            }
    
    
            private void sRecognize_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
            {
                if (e.Result.Text == "exit")
                {
                    Application.Exit();
                }
                else
                {
                    textBox1.Text = textBox1.Text + " " + e.Result.Text.ToString();
                }
    
    
            }
    
    
            private void button3_Click(object sender, EventArgs e)
            {
                sRecognize.RecognizeAsyncStop();
                button2.Enabled = true;
                button3.Enabled = false;
            }
    Quando clicco su start cioè il button 2 l'esecuzione si ferma alla seguente linea: ( sRecognize.RequestRecognizerUpdate(); ) e poi esce dal try ed esegue il catch, non restituisce errore di sintassi ma non scrive niente nella textbox dove dovrebbe scrivere le parole che parlo al microfono cioè quelle inserite nella "sList".
    Qualcuno può aiutarmi?
    Ultima modifica di MItaly; 14-05-2014 a 00:28

Tag per questa discussione

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.