程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程綜合問答 >> kinect-怎樣利用Kinect的麥克風序列進行中文語音識別,只需要識別幾個中文單詞,英文識別已經做出來了。

kinect-怎樣利用Kinect的麥克風序列進行中文語音識別,只需要識別幾個中文單詞,英文識別已經做出來了。

編輯:編程綜合問答
怎樣利用Kinect的麥克風序列進行中文語音識別,只需要識別幾個中文單詞,英文識別已經做出來了。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

using Microsoft.Kinect;
using Microsoft.Speech.AudioFormat;
using Microsoft.Speech.Recognition;

namespace KinectSpeech
{
class Program
{
static void Main(string[] args)
{
KinectSensor KinectSensor = (from k in KinectSensor.KinectSensors
where k.Status == KinectStatus.Connected
select k).FirstOrDefault();
if (KinectSensor == null)
{
Console.WriteLine("No Kinect Connected\n" + "Press any key to continue.\n");
Console.ReadKey(true);
return;
}
KinectSensor.Start();

        KinectAudioSource audioSource = KinectSensor.AudioSource;
        audioSource.EchoCancellationMode = EchoCancellationMode.None;
        audioSource.AutomaticGainControlEnabled = false;

        RecognizerInfo recognizerInfo = GetKinectRecognizer();
        using (var speechRecognitionEngine = new SpeechRecognitionEngine(recognizerInfo.Id))
        {
            var colors = new Choices();
            colors.Add("help");
            colors.Add("green");
            colors.Add("blue");


            var grammatBuilder = new GrammarBuilder { Culture = recognizerInfo.Culture };
            grammatBuilder.Append(colors);
            var g = new Grammar(grammatBuilder);


            speechRecognitionEngine.LoadGrammar(g);
            speechRecognitionEngine.SpeechRecognized += SreSpeechRecognized;
            speechRecognitionEngine.SpeechHypothesized += SreSpeechHypothesized;
            speechRecognitionEngine.SpeechRecognitionRejected += SreSpeechRecognitionRejected;

            using (Stream s = audioSource.Start())
            {
                speechRecognitionEngine.SetInputToAudioStream(
                    s, new SpeechAudioFormatInfo(EncodingFormat.Pcm,
                    16000, 16, 1, 32000, 2, null));

                Console.WriteLine(
                    "Recognizing speech. Say: 'help', 'green' or 'blue'. Press ENTER to stop");

                speechRecognitionEngine.RecognizeAsync(RecognizeMode.Multiple);
                Console.ReadLine();
                Console.WriteLine("Stopping recognizer ...");
                speechRecognitionEngine.RecognizeAsyncStop();
            }
        }
    }


    private static RecognizerInfo GetKinectRecognizer()
    {
        Func<RecognizerInfo, bool> matchingFunc = r =>
        {
            string value;
            r.AdditionalInfo.TryGetValue("Kinect", out value);
            return "True".Equals(value, StringComparison.InvariantCultureIgnoreCase) &&
                "en-US".Equals(r.Culture.Name, StringComparison.InvariantCultureIgnoreCase);
        };
        return SpeechRecognitionEngine.InstalledRecognizers().Where(matchingFunc).
               FirstOrDefault();
    }

    private static void SreSpeechRecognitionRejected(object sender, SpeechRecognitionRejectedEventArgs e)
    {
        Console.WriteLine("\nSpeech Rejected");
        if (e.Result != null)
        {
            DumpRecordedAudio(e.Result.Audio);
        }
    }


    private static void SreSpeechHypothesized(object sender, SpeechHypothesizedEventArgs e)
    {
        Console.Write("\rSpeech Hypothesized: \t{0}", e.Result.Text);
    }


    private static void SreSpeechRecognized(object sender, SpeechRecognizedEventArgs e)
    {
        if (e.Result.Confidence >= 0.7)
        {
            Console.WriteLine("\nSpeech Recognized: \t{0}\tConfidence:\t{1}",
                e.Result.Text, e.Result.Confidence);
        }
        else
        {
            Console.WriteLine("\nSpeech Recognized but confidence was too low: \t{0}",
                e.Result.Confidence);
            DumpRecordedAudio(e.Result.Audio);
        }
    }

    private static void DumpRecordedAudio(RecognizedAudio audio)
    {
        if (audio == null) return;

        int fileId = 0;
        string filename;
        while (File.Exists((filename = "RetainedAudio_" + fileId + ".wav")))
            fileId++;

        Console.WriteLine("\nWriting file: {0}", filename);
        using (var file = new FileStream(filename, System.IO.FileMode.CreateNew))
            audio.WriteToWaveStream(file);
    }
}

}

最佳回答:


目前不支持中文,用發音類似的英文看看

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved