Native Extensions for Silverlight (nesL)在上週时发佈了新的版本,nesL让Silverlight在浏览器外执行(Out-of-browser OOB)时更加增强Silverlight许多功能,它目前有Taskbar的API可以与windows 7的工作列互相搭配,还有像Speech语音功能相关的API等等,而这篇我就简单示範一下用nesL来实作Silverlight的语音朗读功能
首先到下面这网址去下载nesL,我选的是第二个Source这包含了程式码以及相关nesL的librarIEs
http://code.msdn.microsoft.com/nesl/Release/ProjectReleases.aspx?ReleaseID=5368
接着解压缩后在nesLSourceV2_PrevIEw资料夹内路径(SilverlightlibrarIEs\Microsoft.Silverlight.windows.Speech\Bin\Release)下可以找到Microsoft.Silverlight.windows.dll及Microsoft.Silverlight.windows.Speech.dll这两个档案,先分别右键点选这两个档案的内容后,选择解除封锁方便等一下使用
然后在Silverlight专案References中增加Microsoft.Silverlight.windows和Microsoft.Silverlight.windows.Speech的引用
而在介面部分则是很简单的有一个输入方块可以输入要发音的字,以及可以控制发音速度的ComboBox和开始发音的按钮,XAML代码如下:
< UserControl x:Class= "SilverlightSpeech.MainPage"xmlns= "http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x= "http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d= "http://schemas.microsoft.com/Expression/blend/2008"
xmlns:mc= "http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable= "d"
d:DesignHeight= "300" d:DesignWIDth= "400">
< Canvas x:name= "LayoutRoot" Background= "White">
< TextBox Canvas.left= "113" Canvas.top= "16" Height= "45" name= "SpeechWord" WIDth= "246" />
< button Canvas.left= "113" Canvas.top= "122" Content= "Speech" Height= "27" name= "Speechbutton"
WIDth= "72" Click= "Speechbutton_Click" />
< TextBlock Canvas.left= "12" Canvas.top= "34" Height= "27" Text= "輸入要發音的字" WIDth= "93" />
< ComboBox Canvas.left= "113" Canvas.top= "75" Height= "30" name= "RatecomboBox" WIDth= "129" >
< ComboBoxItem Content= "0" IsSelected= "True" />
< ComboBoxItem Content= "5" />
< ComboBoxItem Content= "10" />
< ComboBoxItem Content= "-5" />
< ComboBoxItem Content= "-10" />
< /ComboBox>
< TextBlock Canvas.left= "26" Canvas.top= "82" Height= "27" name= "textBlock2" Text= "速度" WIDth= "55" />
< /Canvas>
< /UserControl>
在程式部分先要引用Microsoft.Silverlight.windows.Speech.Synthesis这个namespace,然后再利用SpeechSynthesizer的Rate属性来控制发音速度,而要发音时唿叫Speak()方法就可以
using System.windows;using System.windows.Controls;
using Microsoft.Silverlight.windows.Speech.Synthesis;
namespace SilverlightSpeech
{
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
}
private voID Speechbutton_Click( object sender, RoutedEventArgs e)
{
SpeechSynthesizer syn = new SpeechSynthesizer();
syn.Rate = int.Parse((RatecomboBox.SelectedItem as ComboBoxItem).Content.ToString());
syn.Speak(SpeechWord.Text);
}
}
}
Silverlight语音朗读(2) 时间:2011-07-29 02:32 来源:dotblogs 作者:eternaltung 点击: 1085次 範例程式到这就完成了,不过nesL必须在OOB模式而且是elevated trust模式下才能执行,因此要允许此Silverlight应用程式可以在浏览器外执行。右键点选到Silverlight专案选择PropertIEs 然后Enable running applicatio
範例程式到这就完成了,不过nesL必须在OOB模式而且是elevated trust模式下才能执行,因此要允许此Silverlight应用程式可以在浏览器外执行。右键点选到Silverlight专案选择PropertIEs
然后Enable running application out of the browser选项打勾,再进入下面OOB settings
在Settings对话方块中,勾选Require elevated trust when running outsIDe the browser
@H_515_403@
接着在执行时,点击滑鼠右键将此Silverlight应用程式安装到电脑上
然后在OOB且为elevated trust模式下,输入发音的字再按发音钮就会发音啰!
在这裡因为我使用的语音是预设的Microsoft Anna,所以并不能发中文音,如果要查看电脑裡有安装的语音可以到控制台裡找语音辨识再选到文字转换语音就可以看到电脑裡安装的语音了
本文来自eternaltung的博客,原文地址:http://www.dotblogs.com.tw/eternaltung/archive/2011/01/26/speechsynthesizer.aspx
总结以上是内存溢出为你收集整理的Silverlight语音朗读全部内容,希望文章能够帮你解决Silverlight语音朗读所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)