小编Luk*_*ood的帖子

如何在C#(语音识别)中使用字符串类型中的&&运算符

我正在使用Microsoft的引擎在C#中编写自己的语音识别程序,并且我使程序识别命令的方式是读取文本文件中已有的内容.这个问题是,我必须完全按照它所写的命令说明.例如,如果命令是"什么是明天日期",我不能说"明天是什么日期".我想办法解决它,那就是使用Contains方法.这是我的代码,

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Speech.Recognition;
using System.Speech.Synthesis;
using System.IO;

namespace TestDECA
{
    public partial class Form1 : Form
    {
        SpeechRecognitionEngine _recognizer = new SpeechRecognitionEngine();
        SpeechSynthesizer DECA = new SpeechSynthesizer();

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            _recognizer.SetInputToDefaultAudioDevice();
            _recognizer.LoadGrammar(new Grammar(new GrammarBuilder(new Choices(File.ReadAllLines(@"D:\Luke's Documents\Speech Commands\TestCommands.txt")))));
            _recognizer.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(_recongizer_SpeechRecognized);
            _recognizer.RecognizeAsync(RecognizeMode.Multiple);
        }

        void _recongizer_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
        {
            string speech = e.Result.Text; …
Run Code Online (Sandbox Code Playgroud)

c# text speech-recognition contains

0
推荐指数
1
解决办法
145
查看次数

如何停止string.Contains()挑选另一个单词中的单词.下面更好的解释

我在我的程序中使用语音识别并且比写出每个可能的单词组合来执行某个命令更容易,我使用.Contains函数来挑选某些关键字.例...

private void SpeechHypothesized(object sender, SpeechHypothesizedEventArgs e)
{
    string speech = e.Result.Text;

    if (speech.Contains("next") && speech.Contains("date"))
    {
        MessageBox.Show(speech + "\nThe date will be the 11th");
    }
    else if (speech.Contains("date"))
    {
        MessageBox.Show(speech + "\nThe date is the 10th");
    }
}
Run Code Online (Sandbox Code Playgroud)

正如您所看到的,如果语音被略微识别,它将显示一个文本框,说出它假设的内容,然后是日期.但是,当我查看文本框中显示的语音时,它会显示"下次更新"之类的内容.因此,该程序正在寻找另一个词,即"更新"内的"日期".我不希望这种情况发生,否则它就不会那么准确,怎么能让.Contains方法自己选出单词,而不是查看其他单词呢?谢谢

c# string contains

0
推荐指数
1
解决办法
109
查看次数

标签 统计

c# ×2

contains ×2

speech-recognition ×1

string ×1

text ×1