惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Martin Fowler
Martin Fowler
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
T
Troy Hunt's Blog
Latest news
Latest news
Vercel News
Vercel News
S
SegmentFault 最新的问题
V
Vulnerabilities – Threatpost
博客园 - Franky
P
Privacy International News Feed
A
Arctic Wolf
T
The Blog of Author Tim Ferriss
S
Schneier on Security
T
The Exploit Database - CXSecurity.com
P
Palo Alto Networks Blog
T
Tor Project blog
Jina AI
Jina AI
GbyAI
GbyAI
The Hacker News
The Hacker News
博客园 - 叶小钗
Google DeepMind News
Google DeepMind News
T
Threatpost
C
CERT Recently Published Vulnerability Notes
P
Proofpoint News Feed
Scott Helme
Scott Helme
WordPress大学
WordPress大学
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Microsoft Azure Blog
Microsoft Azure Blog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
博客园 - 司徒正美
A
About on SuperTechFans
Recorded Future
Recorded Future
爱范儿
爱范儿
L
LangChain Blog
V
V2EX
C
Cybersecurity and Infrastructure Security Agency CISA
The Cloudflare Blog
阮一峰的网络日志
阮一峰的网络日志
K
Kaspersky official blog
Webroot Blog
Webroot Blog
Security Archives - TechRepublic
Security Archives - TechRepublic
D
DataBreaches.Net
宝玉的分享
宝玉的分享
Google Online Security Blog
Google Online Security Blog
C
Cisco Blogs
L
Lohrmann on Cybersecurity
Help Net Security
Help Net Security
AWS News Blog
AWS News Blog
M
MIT News - Artificial intelligence
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
G
GRAHAM CLULEY

博客园 - leon qian

正则表达式全部符号解释 android显示大图片的一些技巧 SAPI 5.1 语音合成的事件 Unicode符号代码表 c#中的问号 C#的四则运算函数 - leon qian - 博客园 读取Excel文件时出现null的解决方法 - leon qian - 博客园 让CSS区别不同浏览器 在Repeater中使用按钮或其他控件的解决方法 - leon qian - 博客园 在IIS中使用Gzip压缩后传送数据 一堆常用JS代码 stream转string,string转stream 一个XML转换的例子 JS代码整理 asp.net 真正意义上的裁减图片 由于启动用户实例的进程时出错的解决方法 C#中的正则表达式 转 SqlHelper详解(转载) [转].net用url重写URLReWriter实现任意二级域名
SAPI 5.1 语音合成的列举语音引擎
leon qian · 2009-08-21 · via 博客园 - leon qian

列举语音[Voices]
翻译说明:由于这个部分涉及到了Delphi编写的简单程序,将其换成C#实现,有些不必要的说明不按照原文翻译,基本上是按照原文复述

本节目标:调整朗读语音,调整语音频率和音量
代码环境设定:两个TrackBar代表语音频率和音量,

trackBarRatetrackBarVolume,一个ComboBox选择朗读语音,comboBoxLanguage
PS:朗读语音,可能会不明白朗读语音的意思,就是在控制面板-语音-文字语音转换-"语音选择"中的项,比如Microsoft Mary,Microsoft Sam等等SpVoiceClass类中GetVoices函数原型如下

public virtual ISpeechObjectTokens GetVoices(string RequiredAttributes, string OptionalAttributes);

该函数返回一个ISpeechObjectToken集合ISpeechObjectTokens,ISpeechObjectToken描述了每个朗读语音
函数两个参数均为对所得到集合的限制,第二参数为对第一参数的补充,比如使用

GetVoices('Gender = male''')

就会得到男声集合
对于这些参数,一般有如下参数:Name,Vendor,Age,Gender,Language[有没有更多的不知道,翻过SAPI的帮助也没找到相关说明]
调用以下语句作以说明

            ISpeechObjectToken sot = svc.GetVoices(String.Empty, String.Empty).Item(0);
            System.Diagnostics.Trace.WriteLine(sot.GetAttribute(
"Name"));
            System.Diagnostics.Trace.WriteLine(sot.GetAttribute(
"Vendor"));
            System.Diagnostics.Trace.WriteLine(sot.GetAttribute(
"Age"));
            System.Diagnostics.Trace.WriteLine(sot.GetAttribute(
"Gender"));
            System.Diagnostics.Trace.WriteLine(sot.GetAttribute(
"Language"));

输出中会显示

Microsoft Mary
Microsoft
Adult
Female
409;9

其中409;9代表该语音支持409[英语]和9[...]语言
[这里原文提到了申请ISpeechObjectToken实例的垃圾处理的问题,由于C#的垃圾处理机制,不翻译了]

必要函数介绍完了,下面是完成目标的代码,很简单,一些没说到的写在了注释里

        SpVoiceClass svc = new SpVoiceClass();
        
private void button1_Click(object sender, EventArgs e)
        
{            
            svc.Volume 
= trackBarVolume.Value;
            svc.Rate 
= trackBarRate.Value;
            svc.Voice 
= svc.GetVoices(string.Empty, string.Empty).Item(comboBoxLanguage.SelectedIndex);
            svc.Speak(textBox1.Text, SpeechVoiceSpeakFlags.SVSFDefault);
        }


        
private void Form1_Shown(object sender, EventArgs e)
        
{
            trackBarRate.Minimum 
= -10;
            trackBarRate.Maximum 
= 10;
            trackBarRate.Value 
= svc.Rate;//Rate取值 -10  10
            trackBarVolume.Maximum = 100;
            trackBarVolume.Value 
= svc.Volume;//Volume取值 0100
            ISpeechObjectTokens sots = svc.GetVoices(String.Empty, String.Empty);
            
int i = 0;
            
foreach (ISpeechObjectToken sot in sots)
            
{
                String str 
= sot.GetDescription(0);//得到语音名称|相当于sot.GetAttribute("name")
                comboBoxLanguage.Items.Add(str);
                
if (str == svc.Voice.GetDescription(0)) comboBoxLanguage.SelectedIndex = i;
                i
++;
            }

        }