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("录音完毕");
                }
               
               
            }

        }
    }

  • 相关阅读:
    2.谈谈算法
    1.数据结构和算法笔记
    初次使用博客
    Unity中关于在一个场景中使用多个摄像机
    基于unity的单例设计模式写法
    unity3D读取Txt文件中信息
    转载雨松的unity中使用ITween插件和ITweenPath
    Unity3D游戏开发之数据持久化PlayerPrefs的使用
    [转载]Unity3d更改3d Text的字体的材质球的shader,使字体不显示
    C#写的Socket Server端在unity运行时和关闭时没事,但是在打开直接unity崩溃问题
  • 原文地址:https://www.cnblogs.com/java20130723/p/3211473.html
Copyright © 2011-2022 走看看