请登录[¤ 阳光论坛 ¤]参与讨论


阳光宝宝
90

 □ 主题: Microsoft Speech SDK的应用
 □ 内容: 1楼

      安装SDK后,运行VB,新建一工程,然后点击菜单“工程”—“引用”,在列表中把Microsoft Speech Object Library引用工程,放入一些控件。下表列出用到的控件及它们的属性 
       
      控件名 属性 属性值  
      text1 text “”  
      command1,2 caption 朗读,退出  
      command3(控件数据) caption +、-、+、-  
      list1(列表框,用来放声音种类)  
      label1,2 caption 速度,音量  
      运行界面如下图  
      源程序如下:  
      Option Explicit  
      Dim WithEvents Vo As SpeechLib.SpVoice  
      Dim vt As SpeechLib.SpObjectToken  
      ''退出程序  
      Private Sub Command2_Click()  
      Unload Me  
      End Sub  
      ''根据控件组增加声速或音量, 声速范围-10-10,音量范围0-100  
      Private Sub Command3_Click(Index As Integer)  
      Select Case Index  
      Case 0  
      If Vo.Rate < 10 Then  
      Vo.Rate = Vo.Rate + 1  
      Call lblchange  
      End If  
      Case 1  
      If Vo.Rate > -10 Then  
      Vo.Rate = Vo.Rate - 1  
      Call lblchange  
      End If  
      Case 2  
      If Vo.Volume < 100 Then  
      Vo.Volume = Vo.Volume + 1  
      Call lblchange  
      End If  
      Case 3  
      If Vo.Volume > 0 Then  
      Vo.Volume = Vo.Volume - 1  
      Call lblchange  
      End If  
      End Select  
      End Sub  
      Private Sub Form_Load()  
      Set Vo = New SpeechLib.SpVoice  
      Label1.Caption = "速度:" & Vo.Rate  
      Label2.Caption = "音量:" & Vo.Volume  
      ''文本框放入的是要朗读的文章  
      Text1.Text = "In order to understand voice events, it is necessary to distinguish between” _  
      & “the TTS engine, which synthesizes speech from text, and the SpVoice object,”_  
      & ” which applications employ to communicate with the engine. The TTS engine is “ _  
      & “somewhat like a server, and the "  
      Call ShowVoice  
      End Sub  
      Private Sub Command1_Click()  
      On Error GoTo Error  
       
      ''根据列表框的选项选择声音,默认为Microsoft Mary.  
      ''也可以通过GetVoices方法,设置声音为男性或女性等  
      ''Set Vo.Voice = Vo.GetVoices("gender=female").Item(0) 声音为女性  
      If List1.ListIndex > -1 Then  
      Set Vo.Voice = Vo.GetVoices.Item(List1.ListIndex)  
      End If  
      Debug.Print Vo.Voice.GetDescription  
      Select Case Command1.Caption  
      Case "朗读"  
      If Not Text1.Text = "" Then  
      ''SVSFlagsAsync 为阅读标记,默认为同步,本例为异步  
      Vo.Speak Text1.Text, SVSFlagsAsync  
      End If  
      Text1.SetFocus  
      Command1.Caption = "暂停"  
      Case "暂停"  
      Vo.Pause  
      Command1.Caption = "继续"  
      Case "继续"  
      Vo.Resume  
      Command1.Caption = "暂停"  
      End Select  
      Exit Sub  
      Error:  
      MsgBox "对不起,朗读出错了", vbOKOnly  
      End Sub  
      ''朗读完毕,把Command1.caption设为朗读  
      Private Sub Vo_EndStream(ByVal StreamNumber As Long, ByVal StreamPosition As Variant)  
      Command1.Caption = "朗读"  
      End Sub  
      Private Sub lblchange()  
      Label1.Caption = "速度:" & Vo.Rate  
      Label2.Caption = "音量:" & Vo.Volume  
      End Sub  
      ''ShowVoice函数取得声音集合,放入列表框  
      Private Sub ShowVoice()  
      For Each vt In Vo.GetVoices  
      List1.AddItem vt.GetDescription  
      Next  
      End Sub  
      ''朗读一个Word(单词),产生一次Word事件,参数StreamPosition为输出声音流中该单词的位置,CharacterPosition为该单词在文本中的位置,Length为单词长度  
      ''通过Word事件,可以直观的看到读到的单词  
      Private Sub Vo_Word(ByVal StreamNumber As Long, ByVal StreamPosition As Variant, ByVal CharacterPosition As Long, ByVal Length As Long)  
      Text1.SelStart = CharacterPosition  
      Text1.SelLength = Length  
      End Sub 
       
      以上程序在VB6+Win98下通过。 
       
      ------------------------------------------------------------------------------------------------------------  
       
      SpVoice对象的属性和方法 
       
       
      属性: 
       
      AlertBoundary 分隔类型,该属性不同,产生的事件就不同  
      AllowAudioOutputFormatChangesOnNextSet 允许用户是否能调整音频格式  
      AudioOutputStream 通过该属性获得由对象SpFileStream打开的文件数据流,然后通过speak方法朗读出来  
      EventInterests 与AlertBoundary类似,用来产生事件的类型  
      Priority 优先权  
      Rate 朗读速度  
      Voice 声音类型  
      Volume 声音大小  
      方法:GetVoices 到得声音类型  
      Speak 开始朗读  
      Pause 暂停  
      Resume 从暂停处开始朗读  
      Skip 跳过若干单词或句子  
      SpeakStream 朗读文件数据流  
      WaitUntilDone 延迟一定时间,单位为毫秒 
       
       
      事件:  
       
      Word 每读完一个单词便产生一次该事件  
      VoiceChange 声音改变就产生  
      Phoneme 每个音位产生  
      EndStream 朗读完毕后产生  
      以上的方法和事件如果与属性AlertBoundary,EventInterests结合就能编出很优秀的程序。欢迎大家与我交流(elby@21cn.com)。 
      
——
      
争分夺秒背单词 → rival  n.竞争者 a.竞争的
 □ 发帖时间:2012-9-21|22:12:44 |回复|返回|



阳光宝宝
90

 □ 主题: 回应:Microsoft Speech SDK的应用
 □ 内容: 2楼

      On Error Resume Next '' 这一句一定要,因为tts不是专门为vb设计的,难免有些数据类型不兼容  
      Dim i As Long  
      For i = 1 To t.CountEngines  
       '' 判断语言id是否为英文  
       '' 注:英文是1033,日文是1041,如果有中文的话那中文就是2052  
       If t.LanguageID(i) = 1033 Then  
       t.Select i  
       Exit For  
       End If  
      Next i  
      t.Speak "hello the world. "  
       
       
      顺便把语言对照表贴出来。  
       
      0x0000 Language Neutral  
      0x0400 Process Default Language  
      0x0401 Arabic (Saudi Arabia)  
      0x0801 Arabic (Iraq)  
      0x0c01 Arabic (Egypt)  
      0x1001 Arabic (Libya)  
      0x1401 Arabic (Algeria)  
      0x1801 Arabic (Morocco)  
      0x1c01 Arabic (Tunisia)  
      0x2001 Arabic (Oman)  
      0x2401 Arabic (Yemen)  
      0x2801 Arabic (Syria)  
      0x2c01 Arabic (Jordan)  
      0x3001 Arabic (Lebanon)  
      0x3401 Arabic (Kuwait)  
      0x3801 Arabic (U.A.E.)  
      0x3c01 Arabic (Bahrain)  
      0x4001 Arabic (Qatar)  
      0x0402 Bulgarian  
      0x0403 Catalan  
      0x0404 Chinese (Taiwan Region)  
      0x0804 Chinese (PRC)  
      0x0c04 Chinese (Hong Kong SAR, PRC)  
      0x1004 Chinese (Singapore)  
      0x0405 Czech  
      0x0406 Danish  
      0x0407 German (Standard)  
      0x0807 German (Swiss)  
      0x0c07 German (Austrian)  
      0x1007 German (Luxembourg)  
      0x1407 German (Liechtenstein)  
      0x0408 Greek  
      0x0409 English (United States)  
      0x0809 English (United Kingdom)  
      0x0c09 English (Australian)  
      0x1009 English (Canadian)  
      0x1409 English (New Zealand)  
      0x1809 English (Ireland)  
      0x1c09 English (South Africa)  
      0x2009 English (Jamaica)  
      0x2409 English (Caribbean)  
      0x2809 English (Belize)  
      0x2c09 English (Trinidad)  
      0x040a Spanish (Traditional Sort)  
      0x080a Spanish (Mexican)  
      0x0c0a Spanish (Modern Sort)  
      0x100a Spanish (Guatemala)  
      0x140a Spanish (Costa Rica)  
      0x180a Spanish (Panama)  
      0x1c0a Spanish (Dominican Republic)  
      0x200a Spanish (Venezuela)  
      0x240a Spanish (Colombia)  
      0x280a Spanish (Peru)  
      0x2c0a Spanish (Argentina)  
      0x300a Spanish (Ecuador)  
      0x340a Spanish (Chile)  
      0x380a Spanish (Uruguay)  
      0x3c0a Spanish (Paraguay)  
      0x400a Spanish (Bolivia)  
      0x440a Spanish (El Salvador)  
      0x480a Spanish (Honduras)  
      0x4c0a Spanish (Nicaragua)  
      0x500a Spanish (Puerto Rico)  
      0x040b Finnish  
      0x040c French (Standard)  
      0x080c French (Belgian)  
      0x0c0c French (Canadian)  
      0x100c French (Swiss)  
      0x140c French (Luxembourg)  
      0x040d Hebrew  
      0x040e Hungarian  
      0x040f Icelandic  
      0x0410 Italian (Standard)  
      0x0810 Italian (Swiss)  
      0x0411 Japanese  
      0x0412 Korean  
      0x0812 Korean (Johab)  
      0x0413 Dutch (Standard)  
      0x0813 Dutch (Belgian)  
      0x0414 Norwegian (Bokmal)  
      0x0814 Norwegian (Nynorsk)  
      0x0415 Polish  
      0x0416 Portuguese (Brazilian)  
      0x0816 Portuguese (Standard)  
      0x0418 Romanian  
      0x0419 Russian  
      0x041a Croatian  
      0x081a Serbian (Latin)  
      0x0c1a Serbian (Cyrillic)  
      0x041b Slovak  
      0x041c Albanian  
      0x041d Swedish  
      0x081d Swedish (Finland)  
      0x041e Thai  
      0x041f Turkish  
      0x0421 Indonesian  
      0x0422 Ukrainian  
      0x0423 Belarusian  
      0x0424 Slovenian  
      0x0425 Estonian  
      0x0426 Latvian  
      0x0427 Lithuanian  
      0x0429 Farsi  
      0x042a Vietnamese  
      0x042d Basque  
      0x0436 Afrikaans  
      0x0438 Faeroese
——
      
争分夺秒背单词 → final  a.最后的;决定性的
 □ 发帖时间:2012-9-21|22:22:08 |回复|返回|

 页次:1/1页 每页10  本主题贴数1 分页: 1


你还没有登录论坛,所以不能发表你的意见。你可以选择:

1、我已注册,我要

2、我还没注册,我要

3、太麻烦了,我还是

Go Top

Copyright by(C)2003-2015 http://abc.sy578.cn