在Unity中使用Vosk实现语音识别

  • 在获得识别结果时注册回调。此回调提供语音识别结果字符串。
    [En]

    register the callback when the recognition result is obtained. This callback provides the speech recognition result string.*

voskSpeechToText.OnTranscriptionResult += OnTranscriptionResult;
  • 正则表达式匹配 导入包
using System.Text.RegularExpressions;

实例化

Regex hi_regex = new Regex(@"你好");
  • OnTranscriptionResult 对应的注册事件中实现根据识别结果执行对应逻辑
private void OnTranscriptionResult(string obj)
{

    Debug.Log(obj);
    var result = new RecognitionResult(obj);
    foreach (RecognizedPhrase p in result.Phrases)
    {

        var asrText = p.Text.Replace(" ", "");
        if (hi_regex.IsMatch(asrText))
        {
            Debug.Log("你好,我是小智");
            break;
        }

    }
}

Original: https://blog.csdn.net/weixin_41260141/article/details/125404326
Author: CusomeLeyen
Title: 在Unity中使用Vosk实现语音识别

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/527149/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球