c#语音识别如何在特定单词之后得到剩下的单词

本文关键字:单词 之后 语音识别 | 更新日期: 2023-09-27 18:11:30

语音搜索关键字困难。我想通过获得特定的关键词后获得搜索关键字。

Speak statement = banana color is yellow

具体来说,"香蕉的颜色是"。结果应该是"黄色"。

SpeechSynthesizer SS = new SpeechSynthesizer
PromptBuilder Pb = new PromptBuilder();
SpeechRecognitionEngine re = new SpeechRecognitionEngine();
Choices list = new Choices();
list.Add(news string[]{"banana color is "});
switch (e.Result.Text.To String()){
case "banana color is":
//I want it to display in textbox
//search Textbox.Append Text();
break;
}

thanks in advance

c#语音识别如何在特定单词之后得到剩下的单词

为什么不使用String.Split

var split = e.Result.Text.Split(list[0]);

这样你将得到一个字符串[],其中包含了拆分后的结果。

split[0] = list[0]
split[1] = // the remaining text

我也试了一下,你可以在底部看到一个分辨率。总的来说,我不得不说语音识别引擎在言论自由方面有点糟糕

SpeechRecognitionEngine h = new SpeechRecognitionEngine();
SpeechSynthesizer s = new SpeechSynthesizer();
private void Form1_Load(object sender, EventArgs e)
{
    Choices commands = new Choices();
    commands.Add(new string[] { "command one", "command two", "Dictate" });
    GrammarBuilder gbuilder = new GrammarBuilder();
    gbuilder.Append(commands);
    gbuilder.AppendDictation();
    Grammar grammar = new Grammar(gbuilder);
    h.LoadGrammar(grammar);
    h.SetInputToDefaultAudioDevice();
    h.SpeechRecognized += recEngine_SpeechRecognized;
    h.RecognizeAsync(RecognizeMode.Multiple);
    s.SelectVoiceByHints(VoiceGender.Female, VoiceAge.Adult);
    s.SpeakAsync("Wie kann ich dir helfen");
}
void recEngine_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
    if (e.Result.Text.StartsWith("command one"))
    {
    s.SpeakAsync("Command one");
    }
    else if (e.Result.Text.StartsWith("wie spät ist es"))
    {
        s.SpeakAsync("Command two");
    }
    else if (e.Result.Text.StartsWith("Dictate"))
    {
        s.SpeakAsync(e.Result.Dictate);
        lbl_ans.Text = e.Result.Text; //gets all text till you stoped talking
    }
}