/// <summary>
 /// 关闭语音识别方法
 /// </summary>
 /// <param name="provider"></param>
 /// <param name="callback"></param>
 /// <returns></returns>
 public static async Task CloseAsync(this IRecognizerProvider provider, Func <RecognizerStatus, string?, Task> callback)
 {
     var option = new RecognizerOption()
     {
         MethodName = "bb_azure_close_recognizer",
         Callback   = callback
     };
     await provider.InvokeAsync(option);
 }
Exemple #2
0
 /// <summary>
 /// 关闭语音识别方法
 /// </summary>
 /// <param name="provider"></param>
 /// <param name="callback"></param>
 /// <returns></returns>
 public static async Task CloseAsync(this IRecognizerProvider provider, Func <RecognizerStatus, string?, Task>?callback = null)
 {
     var option = new RecognizerOption()
     {
         MethodName = "bb_baidu_speech_close",
         Callback   = callback
     };
     await provider.InvokeAsync(option);
 }
Exemple #3
0
        public async Task InvokeAsync(RecognizerOption option)
        {
            var method              = option.MethodName;
            var language            = option.TargetLanguage;
            var recognitionLanguage = option.SpeechRecognitionLanguage;

            if (option.Callback != null)
            {
                await option.Callback(RecognizerStatus.Start, "MockSpeechProvider");
            }
        }
 /// <summary>
 /// 回调方法
 /// </summary>
 /// <param name="option"></param>
 /// <returns></returns>
 /// <exception cref="InvalidOperationException"></exception>
 public async Task InvokeAsync(RecognizerOption option)
 {
     if (!string.IsNullOrEmpty(option.MethodName))
     {
         Option = option;
         if (Module == null)
         {
             var moduleName = "./_content/BootstrapBlazor.BaiduSpeech/js/recognizer.js";
             Logger.LogInformation($"load module {moduleName}");
             Module = await JSRuntime.InvokeAsync <IJSObjectReference>("import", moduleName);
         }
         Interop ??= DotNetObjectReference.Create(this);
         await Module.InvokeVoidAsync(Option.MethodName, Interop, nameof(RecognizeCallback), Option.AutoRecoginzerElapsedMilliseconds);
     }
 }
Exemple #5
0
    /// <summary>
    /// 语音识别方法
    /// </summary>
    /// <param name="provider"></param>
    /// <param name="callback"></param>
    /// <param name="autoRecoginzerElapsedMilliseconds">默认 5000 毫秒后自动识别,设置 0 时禁用</param>
    public static async Task RecognizeOnceAsync(this IRecognizerProvider provider, Func <RecognizerStatus, string?, Task> callback, int?autoRecoginzerElapsedMilliseconds = null)
    {
        var option = new RecognizerOption()
        {
            MethodName = "bb_baidu_speech_recognizeOnce",
            Callback   = callback
        };

        // 设置自动识别时间
        if (autoRecoginzerElapsedMilliseconds.HasValue)
        {
            option.AutoRecoginzerElapsedMilliseconds = autoRecoginzerElapsedMilliseconds.Value;
        }
        await provider.InvokeAsync(option);
    }
Exemple #6
0
    /// <summary>
    /// 回调方法
    /// </summary>
    /// <param name="option"></param>
    /// <returns></returns>
    public async Task InvokeAsync(RecognizerOption option)
    {
        if (!string.IsNullOrEmpty(option.MethodName))
        {
            // 通过 SubscriptionKey 交换 Token
            var token = await ExchangeToken();

            Option = option;
            if (Module == null)
            {
                Module = await JSRuntime.InvokeAsync <IJSObjectReference>("import", "./_content/BootstrapBlazor.AzureSpeech/js/speech.js");
            }
            Interop ??= DotNetObjectReference.Create(this);
            await Module.InvokeVoidAsync(Option.MethodName, Interop, nameof(Callback), token, SpeechOption.Region, option.SpeechRecognitionLanguage, option.TargetLanguage, option.AutoRecoginzerElapsedMilliseconds);
        }
    }
    public async Task Recognizer_Ok()
    {
        var result            = "";
        var recognizerService = Context.Services.GetRequiredService <RecognizerService>();
        var option            = new RecognizerOption()
        {
            MethodName                        = "Test",
            TargetLanguage                    = "zh-CN",
            SpeechRecognitionLanguage         = "zh-CN",
            AutoRecoginzerElapsedMilliseconds = 5000,
            Callback = new Func <RecognizerStatus, string?, Task>((status, v) =>
            {
                result = v;
                return(Task.CompletedTask);
            })
        };
        await recognizerService.InvokeAsync(option);

        Assert.Equal("MockSpeechProvider", result);
        Assert.Equal(5000, option.AutoRecoginzerElapsedMilliseconds);
    }
 /// <summary>
 /// 语音识别回调方法
 /// </summary>
 /// <param name="option"></param>
 /// <returns></returns>
 public Task InvokeAsync(RecognizerOption option) => Provider.InvokeAsync(option);