private async void Timer_Tick(object sender, object e) { Console.WriteLine("Ailemon.Asrt.AsrtClientProxy: 录音周期流式传输"); // 定时从缓存中读取wave数据,并送去语音识别 Stream waveMemStream = _audioRecorder.PopMemoryStream(); WaveData wav = SDK.ReadWaveDatas(waveMemStream); AsrtApiResponse rsp = (AsrtApiResponse)await _speechRecognizer.RecogniteAsync(wav.byteWavs, wav.sampleRate, wav.channels, wav.byteWidth); AsrtResult result = new AsrtResult((string)rsp.Result, true, rsp.StatusCode, rsp.StatusMessage); OnReceiveText(this, result); }
/// <summary> /// 异步停止客户端调用ASRT语音识别 /// </summary> public async void StopAsync() { if (_isRecognizing) { timer.Stop(); Console.WriteLine("Ailemon.Asrt.AsrtClientProxy: 停止录音识别"); try { // 从缓存中读取wave数据,并送去语音识别 Stream waveMemStream = _audioRecorder.Stop(); WaveData wav = SDK.ReadWaveDatas(waveMemStream); AsrtApiResponse rsp = (AsrtApiResponse)await _speechRecognizer.RecogniteAsync(wav.byteWavs, wav.sampleRate, wav.channels, wav.byteWidth); AsrtResult result = new AsrtResult((string)rsp.Result, true, rsp.StatusCode, rsp.StatusMessage); OnReceiveText(this, result); //产生事件 } catch (Exception ex) { string str = ex.Message; } _isRecognizing = false; } }