c# - 如何获取语音数据?

标签 c# .net windows speech-recognition

在我的程序中,我可以使用用户的声音来获取词典、文本、单词等等。但是,有什么办法可以获取用户声音的音高吗?我正在使用带有 c# 的 Windows 语音 API。

以下是我用来获取语音数据的部分代码

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Speech.Recognition;
using System.Speech.Synthesis;
using System.Windows.Forms;
using System.IO;

namespace Speech_Recognizer
{
    public class RecognizeSpeech
    {
        private SpeechRecognitionEngine sEngine; //Speech recognition engine
        private SpeechSynthesizer sSpeak; //Speech synthesizer
        string text3 = "";

        public RecognizeSpeech()
        {
            //Make the recognizer ready
            sEngine = new SpeechRecognitionEngine(new System.Globalization.CultureInfo("en-US"));


            //Load grammar
            Choices sentences = new Choices();
            sentences.Add(new string[] { "I am hungry" });

            GrammarBuilder gBuilder = new GrammarBuilder(sentences);

            Grammar g = new Grammar(gBuilder);

            sEngine.LoadGrammar(g);

            //Add a handler
            sEngine.SpeechRecognized +=new EventHandler<SpeechRecognizedEventArgs>(sEngine_SpeechRecognized);


            sSpeak = new SpeechSynthesizer();
            sSpeak.Rate = -2;



            //Computer speaks the words to get the phones
            Stream stream = new MemoryStream();
            sSpeak.SetOutputToWaveStream(stream);


            sSpeak.Speak("I was hungry");
            stream.Position = 0;
            sSpeak.SetOutputToNull();


            //Configure the recognizer to stream
            sEngine.SetInputToWaveStream(stream);

            sEngine.RecognizeAsync(RecognizeMode.Single);


        }


        //Start the speech recognition task
        private void sEngine_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
        {
            string text = "";

            if (e.Result.Text == "I am hungry")
            {
                foreach (RecognizedWordUnit wordUnit in e.Result.Words)
                {
                    text = text + wordUnit.Pronunciation + "\n";
                }

                MessageBox.Show(e.Result.Text + "\n" + text);
            }


        }
    }
}

如您所见,SpeechSynthesizer 可以设置和获取语速、声音等。如何从用户语音中获取音调?我可以获取任何其他信息吗?

最佳答案

不,Microsoft SR 引擎不会从用户的声音中返回音调数据。

关于c# - 如何获取语音数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16893049/

相关文章:

.net - 检查hangfire重复作业是否已经在运行

c# - .Net Framework 3.5 反射问题

c# - 通过动态 : . NET/C# 框架错误访问泛型类型成员时出现 StackOverflowException?

windows - 新电脑,git pull origin 要求输入密码

windows - 使窗口只运行一个用户可见的程序

c# - 在 C# 中将整个 xml 文件复制到其他 xml

c# - Entity Framework - 不支持列 'ColumnName' 的类型。类型是 'Object'

c++ - 使c++程序在windows中的特定核心上运行

c# - 你如何在 ASP.NET MVC 中本地化日期

c# - 负向后视的小数或整数