【问题标题】:Free speech recognition for C# WinForm AppC# WinForm App 的免费语音识别
【发布时间】:2017-04-17 10:48:14
【问题描述】:

我正在尝试为 C# Windows Form Application 可执行文件寻找免费的语音识别,它可以用作 Google 语音识别,识别新单词并将其转换为文本。

我尝试使用 System.Speech.Recognition;不同的方式,但它适用于预先录制的命令,我无法获得这样的结果,因为它可以与 Python 的 Google Speech Recognition 一起使用,这至少是 95% 的正确结果,足以说,这很好,但显然,如果我没有密钥,它就不能免费使用,也不能在可执行文件中使用。

所以我想尝试 Microsoft Cognitive Services 的 Bing Speech API,但找不到任何如何编码的示例,一些基本示例。如果有人处理过这个工具,你能帮我弄清楚吗

【问题讨论】:

标签: speech-recognition speech-synthesis google-speech-api microsoft-speech-platform microsoft-speech-api


【解决方案1】:

嗨,也许这可以帮助你一个简单的 bing 语音 api 示例,这不是 winform 这是用于 WPF 应用程序 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;
            }));
        }
    }
}

【讨论】:

  • 你好,关键在哪里,它一定在代码中吧?我在microsoft.com/cognitive-services/en-US/subscriptions 上有两个键,隐藏为 XXXXXXXXXXXXXXXXXXXXXXXXXXX,所以这个地方是字符串subscriptionKey = ConfigurationManager.AppSettings["MicrosoftSpeechApiKey"].ToString(); ?
  • 是的,您必须在 app.config 文件中添加密钥
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-12-23
  • 2018-02-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多