1

I'm trying to find free speech recognition for C# Windows Form Application executable, which can work as Google Speech Recognition, recognize and convert absolutely new words to text.

I tried to use System.Speech.Recognition; different ways, but it is works good for prerecorded commands and I can't get such results as it works with Google Speech Recognition with Python for example, which is 95% correct results at least, more then enough to say, that is good, but apparently if I do not have a key it is not available for free and to use it in executable.

So I want try Bing Speech API of Microsoft Cognitive Services, but can't find any example how to code it, some basic example. If someone have deal with this tool, can you help me figure out

nikorio
  • 671
  • 4
  • 16
  • 28

1 Answers1

1

Hi maybe this can help you a simple bing speech api example, this is not winform this is for WPF Application C#

using Microsoft.CognitiveServices.SpeechRecognition;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Microsoft.ProjectOxford.SpeechRecognition;
using System.Threading;
using System.Configuration;

namespace BingSpeech
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        AutoResetEvent _FinalResponceEvent;
        MicrophoneRecognitionClient _microphoneRecognitionClient;
        public MainWindow()
        {
            InitializeComponent();
            RecordButton.Content = "Start\nRecording";
            _FinalResponceEvent = new AutoResetEvent(false);
            OutputTextbox.Background = Brushes.White;
            OutputTextbox.Foreground = Brushes.Black;
        }

        private void RecordButton_Click(object sender, RoutedEventArgs e)
        {
            RecordButton.Content = "Listening ...";
            RecordButton.IsEnabled = false;
            OutputTextbox.Background = Brushes.Green;
            OutputTextbox.Foreground = Brushes.White;
            ConvertSpeechToText();
        }

        private void ConvertSpeechToText()
        {
            var speechRecognitionMode = SpeechRecognitionMode.ShortPhrase;
            string language = "en-us";
            string subscriptionKey = ConfigurationManager.AppSettings["MicrosoftSpeechApiKey"].ToString();
            _microphoneRecognitionClient = SpeechRecognitionServiceFactory.CreateMicrophoneClient(
                speechRecognitionMode,
                language,
                subscriptionKey
                 );
            _microphoneRecognitionClient.OnPartialResponseReceived += OnPartialResponseReceivedHandler;
            _microphoneRecognitionClient.OnResponseReceived += OnMicShortPhraseResponceReceivedHandler;
            _microphoneRecognitionClient.StartMicAndRecognition();
        }

        private void OnPartialResponseReceivedHandler(object sender, PartialSpeechResponseEventArgs e)
        {
            string result = e.PartialResult;
            jarvis.SpeakAsync(e.PartialResult);
            Dispatcher.Invoke(() =>
            {
                OutputTextbox.Text = (e.PartialResult);
                OutputTextbox.Text += ("\n");

            });
        }
        private void OnMicShortPhraseResponceReceivedHandler(object sender, SpeechResponseEventArgs e)
        {
            Dispatcher.Invoke((Action)(() =>
            {
                _FinalResponceEvent.Set();
                _microphoneRecognitionClient.EndMicAndRecognition();
                _microphoneRecognitionClient.Dispose();
                _microphoneRecognitionClient = null;
                RecordButton.Content = "Start\nRecording";
                RecordButton.IsEnabled = true;
                OutputTextbox.Background = Brushes.White;
                OutputTextbox.Foreground = Brushes.Black;
            }));
        }
    }
}
Apsdevs00698
  • 227
  • 1
  • 2
  • 9
  • Hello, and where the key goes, it must be in the code right? I have two keys on https://www.microsoft.com/cognitive-services/en-US/subscriptions, which hidden as XXXXXXXXXXXXXXXXXXXXXXXXXXX so the place is string `subscriptionKey = ConfigurationManager.AppSettings["MicrosoftSpeechApiKey"].ToString();` ? – nikorio Dec 09 '16 at 19:16
  • Yes you have to add key to app.config file – Apsdevs00698 Feb 20 '17 at 10:42