zoukankan      html  css  js  c++  java
  • 录音和朗诵的实现

    如何实现语音和朗诵的功能:

    using System;
    using System.Windows.Forms;
    using System.IO;
    using System.Media;
    using System.Runtime.InteropServices;

    namespace 播放TTS
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
            //根目录
            string address = System.AppDomain.CurrentDomain.BaseDirectory;
            private void btnPlay_Click(object sender, EventArgs e)
            {
               
                foreach (string s in textBox1.Text.Split(' '))
                {
                    //string wavFile = @".\Video" + s + ".wav";
                    string wavFile = address+@"Video\" + s.ToLower() + ".wav";
                    if (File.Exists(wavFile))
                    {
                        SoundPlayer sp = new SoundPlayer(wavFile);
                        sp.PlaySync();
                    }
                }
            }
            [DllImport("winmm.dll", EntryPoint = "mciSendString", CharSet = CharSet.Auto)]
            private static extern int mciSendString(
             string lpstrCommand,
             string lpstrReturnString,
             int uReturnLength,
             int hwndCallback
            );

            private static void mciSendString(String cmd)
            {
                mciSendString(cmd, "", 0, 0);
            }

            private static void StartRecord()
            {
                mciSendString("close movie");
                mciSendString("open new type WAVEAudio alias movie");
                mciSendString("record movie");
            }

            private static void StopRecord(string filename)
            {
                mciSendString("stop movie");
                mciSendString("save movie " + filename);
                mciSendString("close movie");
            }

            //开始录音
            private void btnBegin_Click(object sender, EventArgs e)
            {
                StartRecord();
            }

            private void btnStop_Click(object sender, EventArgs e)
            {
                string title = ttbTitle.Text;
                string saveAddress = address + @"\Video\" + title.ToLower() + ".wav";
                if (File.Exists(saveAddress))
                {
                    MessageBox.Show("文件已存在,重命名");
                }
                else
                {
                    StopRecord(saveAddress);
                    MessageBox.Show("录音完毕");
                }
               
               
            }

        }
    }

  • 相关阅读:
    java web 工程更改名字
    [转]Eclipse下开发Struts奇怪异常:org.apache.struts.taglib.bean.CookieTei
    【转】myeclipse 自定义视图Customize Perspective 没有反应
    latex建立参考文献的超链接
    latex 脚注编号也成为超链接
    自定义标签TLD文件中,rtexprvalue子标签的意思
    设计模式观察者
    设计模式模板方法
    设计模式策略
    设计模式享元
  • 原文地址:https://www.cnblogs.com/java20130723/p/3211473.html
Copyright © 2011-2022 走看看