yuanchaost

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

  private void Button_Click(object sender, RoutedEventArgs e)
        {
            SpeechVideo_Read(2, 100, "You came to me Like the dawn through the night Just shining like the sun.");
        }

        public void SpeechVideo_Read(int rate, int volume, string speektext)  //读
        {
            speech.Rate = rate;
            speech.Volume = volume;
            speech.SpeakAsync(speektext);
        }

  public void SpeechVideo_Record(int rate, int volume, string recordtext)  //录音
        {
            SpeechSynthesizer speech = new SpeechSynthesizer();
            speech.Rate = rate;
            speech.Volume = volume;
            SaveFileDialog sfd = new SaveFileDialog();
            sfd.Filter = "文本文件(*.wav)|*.wav|所有文件(*.*)|*.*";
            //设置默认文件类型显示顺序
            sfd.FilterIndex = 1;
            //保存对话框是否记忆上次打开的目录
            sfd.RestoreDirectory = true;
            if (sfd.ShowDialog()== System.Windows.Forms.DialogResult.OK)
            {
                string localfilepath = sfd.FileName.ToString();
                speech.SetOutputToWaveFile(localfilepath);
                speech.Speak(recordtext);
                speech.SetOutputToDefaultAudioDevice();
                System.Windows.MessageBox.Show("完成录音!", "提示");
            }
        }

posted on 2020-08-12 18:00  yuanchaost  阅读(564)  评论(0编辑  收藏  举报