zoukankan      html  css  js  c++  java
  • C# 文本转语音,在语音播放过程中停止语音

    1,运用SpVoice播放语音

    在VS2013创建Windows窗体应用程序项目,添加引用COM组件Microsoft Speech Object Library:

    using SpeechLib;
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    
    namespace 测试
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }         
            private void button1_Click(object sender, EventArgs e)
            {
               SpVoice voice = new SpVoice();
                voice.Rate = -2; //语速,[-10,10]
                voice.Volume = 100; //音量,[0,100]
                voice.Voice = voice.GetVoices().Item(0); //语音库
                voice.Speak("hello word!");
            }  
        }
    }

    2,SpeechSynthesizer ,语音播放过程中停止

    使用该类必须要添加引用using System.Speech.Synthesis;直接是无法添加引用的,先对项目进行添加应用

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Speech.Synthesis;
    using System.Text;
    using System.Threading;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    
    namespace 测试
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
            SpeechSynthesizer speak = new SpeechSynthesizer(); 
            private void button1_Click(object sender, EventArgs e)
            {
                speak.Dispose();
                speak = new SpeechSynthesizer();
                speak.Volume = 100;
                speak.Rate = -1;
                speak.SpeakAsync("The company has six series of products, facing the four markets of higher education, community education, cadre education and children's education. It is a professional and comprehensive provider of digital lifelong learning solutions.");
            }       
            private void button2_Click(object sender, EventArgs e)
            {
                speak.Pause();            
        }
    }

    此方法适用于WindowForm窗体应用程序,文本程序需要把页面设成异步

  • 相关阅读:
    iOS开发之字符串去掉首尾空格换行
    iOS开发之截取UIScrollView长图方法、截长图
    iOS开发之语音录制
    iOS开发之程序各种状态监听
    iOS开发之监听应用进入前台后台
    iOS开发之波浪动画效果
    mysql 主从一致性检查
    git 备份和恢复
    tomcat server.xml配置文件 解析
    检查MySQL主从数据一致性
  • 原文地址:https://www.cnblogs.com/lcidy/p/10143410.html
Copyright © 2011-2022 走看看