调用 Windows 7 中英文混合朗读

1、windows7内置语音识别

2、文本到语音转换增加了 Microsoft Lili - Chinese(China) ,支持中英文混合朗读

3、女声、部分词组基本发音准确

 

以上让我有做个小程序的冲动;如下:

 

1、引入SpeechLib.dll

2、创建form

3、编写代码

 

复制代码
复制代码

    
public partial class FormMain : Form
    {
        
public FormMain()
        {
            InitializeComponent();
        }

        
private void FormMain_Load(object sender, EventArgs e)
        {
            GetVoices();
        }

        
private void GetVoices()
        {
            SpVoice voice 
= new SpVoiceClass();
            ISpeechObjectTokens voices 
= voice.GetVoices("""");
            var list 
= new List<string>();
            
foreach (ISpeechObjectToken token in voices)
                list.Add(token.GetDescription(
0));
            cbSpeechType.DataSource 
= list;
        }

        
private void btnSpeechText_Click(object sender, EventArgs e)
        {
            SpeechText(
null);
        }

        
private void SpeechText(string fileName)
        {
            Cursor 
= Cursors.WaitCursor;
            SpFileStream stream 
= null;
            SpVoice voice 
= new SpVoiceClass();
            
if (fileName + "" != "")
            {
                stream 
= new SpFileStreamClass();
                stream.Open(fileName, SpeechStreamFileMode.SSFMCreateForWrite, 
false);
                voice.AudioOutputStream 
= stream;
            }
            voice.Voice 
= voice.GetVoices("""").Item(cbSpeechType.SelectedIndex);
            voice.Volume 
= tbVol.Value;
            voice.Rate 
= tbSpeechSpeed.Value;
            voice.Speak(tbText.Text, SpeechVoiceSpeakFlags.SVSFDefault);
            
if (fileName + "" != "" && stream != null)
                stream.Close();
            Cursor 
= Cursors.Arrow;
        }

        
private void btnRecordSpeech_Click(object sender, EventArgs e)
        {
            Cursor 
= Cursors.WaitCursor;
            
using (var saveFileDialog = new SaveFileDialog())
            {
                saveFileDialog.FileName 
= "MyVoice.wav";
                saveFileDialog.Filter 
= "Wave (*.wav)|*.wav";
                
if (saveFileDialog.ShowDialog() == DialogResult.OK)
                {
                    SpeechText(saveFileDialog.FileName);
                }
            }
            Cursor 
= Cursors.Arrow;
        }
    }
复制代码
复制代码

 

以上功能支持朗读文本框内文本,支持讲文本输出语音文件;

 

参考应用场景:

1、尝尝鲜,再删除

2、将小说文本转化为音频放MP3内去听

3、骗骗小孩

 

运行环境需求:

1、WINDOWS 7

2、其他未知

 

 

说再多不如放个代码,所以本文从简,请下载后编译运行。

 

AnySpeech.rar

 

出处:http://www.cnblogs.com/Chinasf/archive/2010/01/04/1639282.html

posted on   jack_Meng  阅读(940)  评论(0编辑  收藏  举报

编辑推荐:
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示

喜欢请打赏

扫描二维码打赏

支付宝打赏

主题色彩