调用 Windows 7 中英文混合朗读

本文介绍了一个基于Windows7的文本转语音小程序实现方法,利用SpeechLib.dll进行文本朗读及输出为语音文件,适用于小说转音频等场景。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值