怎样利用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);
    }
}

}

2个回答

目前不支持中文,用发音类似的英文看看

as199581tg
丶小柒灬 网上有回答说是可以用speech sdk 5.1版本加上中文语言包进行中文语音识别,难道现在还没人做出来么
大约 5 年之前 回复

安装中文语音包就可以实现,我在Kinect1.0上用过没问题的, V2的还没时间试

oqqsail
一只大蘑菇 回复qq_37752927: 您好,我现在也是在做kinect中文语音识别遇到这个问题了,请问您的问题解决了吗
接近 3 年之前 回复
qq_37752927
qq_37752927 您好,下载了中文语言包,可以将文字转化成语音控制发音,请问用kinect怎么进行中文语音识别啊
3 年多之前 回复
sinat_34327163
sinat_34327163 求问中文语音包在哪能下 谢谢!
4 年多之前 回复
立即提问
相关内容推荐