Пример #1
0
        private void btnTts_Click(object sender, EventArgs e)
        {
            // 临时保存路径
            var musicPath = Path.Combine("temp", Guid.NewGuid() + ".mp3");

            // 发言人
            var per = cbPer.SelectedIndex >= 2 ? cbPer.SelectedIndex + 1 : cbPer.SelectedIndex;

            //调用Baidu TTS Api
            if (!SpeechHelper.Tts(tbContext.Text, musicPath, (int)nudSpd.Value, (int)nudPit.Value, (int)nudVol.Value, per))
            {
                return;
            }

            //播放请求得到的结果
            IWavePlayer waveOutDevice   = new WaveOut();
            var         audioFileReader = new AudioFileReader(musicPath);

            waveOutDevice.Init(audioFileReader);
            waveOutDevice.Play();

            //播放结束后销毁播放对象
            waveOutDevice.PlaybackStopped += delegate
            {
                waveOutDevice?.Stop();
                waveOutDevice?.Dispose();
                waveOutDevice = null;
            };
        }
Пример #2
0
        private void OnStopRecordingClick(object sender, EventArgs e)
        {
            // 停止录制
            _recorder.StopRecording();
            // 停止播放
            _player.Stop();
            // 最终完成 WAV 文件
            _savingWaveProvider.Dispose();
            Log("停止录制");

            Log("请求百度ASR接口");
            var a = SpeechHelper.AsrData(_fileName);


            Log($"请求结果:{a.Result.Serialize()}");
        }