private async void Timer_Tick(object sender, object e) { this._audioRecorder.StopRecording(); string filename = "speechfile" + i_audioRecorder.ToString() + ".wav"; await this._audioRecorder.SaveAudioToFile(filename); //保存完文件后立即继续录音 i_audioRecorder++; this._audioRecorder = pool_audioRecorder[i_audioRecorder % 2]; this._audioRecorder.Record(); pool_audioRecorder[(i_audioRecorder + 1) % 2] = new AudioRecorder(); //timer.Stop(); //MessageBox.Visibility = Visibility.Collapsed; string text = ""; try { text = await SpeechRecognizeAsync(filename); } catch (Exception ex) { string str = ex.Message; } this.text_note.Text += text; //滚动到最后 text_note.SelectionStart = text_note.Text.Length; ScrollViewer.ChangeView(0.0f, double.MaxValue, 1.0f); // 识别完成后删除文件 DelWavFile(filename); }
public MainPage() { this.InitializeComponent(); pool_audioRecorder[0] = new AudioRecorder(); pool_audioRecorder[1] = new AudioRecorder(); this._audioRecorder = pool_audioRecorder[0]; MessageBox.Visibility = Visibility.Collapsed; }