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窗体应用程序,文本程序需要把页面设成异步

  • 相关阅读:
    [Git & GitHub] 利用Git Bash进行第一次提交文件
    Linux下 Unison 实现文件双向同步
    Linux SSH使用公钥私钥实现免登陆
    SSH自动断开连接的原因
    hosts.deny 和hosts.allow 配置不生效
    bind启动时提示953端口被使用
    Linux查询系统配置常用命令
    Linux 查硬件配置
    BIND rndc—使用说明
    rndc 错误解决 和 远程配置
  • 原文地址:https://www.cnblogs.com/lcidy/p/10143410.html
Copyright © 2011-2022 走看看