高分求教?????

lfd_boy 2002-03-28 09:58:59
谁有用vc做的TextToSpeech控件发音的例子???非常感谢!!
...全文
98 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
Kaile 2002-03-28
  • 打赏
  • 举报
回复
下面是MSDN中的例子,原理知道后很容易转为VC
A Sample Application: Speak2Me
This sample application was written to demonstrate just how easy it is to use the VTxtAuto ActiveX COM object. The sample does one of two things. The user can type in text and have that text spoken when they click on a button, or the application can be set to monitor the clipboard and speak its contents whenever it changes.

The single form is as shown in Figure 1.



Figure 1. The clipboard speaker form

The form has only five "moving parts": the editbox, the Speak button, the Exit button, the Monitor clipboard checkbox, and an invisible timer control. Whenever the Speak button is clicked then the text in the editbox will be spoken via the TTS engine.

If the Monitor clipboard checkbox is checked, then whenever the contents of the clipboard change the contents are placed into the editbox and then "spoken." This feature demonstrates a possible use for visually impaired people. With this sample application running in the background, all they would have to do is highlight a piece of text in a word processor, transfer it to the clipboard, and hear it spoken. The rate at which the clipboard is sampled is determined by the interval set on the timer control.

Design
The code for the sample is very straightforward and should be self-explanatory. The only part that requires a more detailed explanation is the setup of the callback class module. I'll examine the core code of the sample first, and then go into detail about the callback code.

The form (frmMain) contained in the file frmMain.frm contains the following code (some incidental code has either been eliminated or reduced for brevity).

Option Explicit
Dim oVoice As VTxtAuto.VTxtAuto 'Voice object
Dim bTimerLoop As Boolean 'Looping constraint
Dim bMonitorClipboard As Boolean 'Toggle for clipboard monitoring

The code below is invoked when the Speak button is clicked. This code is used in two ways: to start the speaking or to end the speaking. The caption on the button toggles between "Start" and "Stop." The callback routine is the actual code that changes the caption. The bMonitorClipboard variable is used to determine whether or not to speak via the timer code, or to simply speak the current contents of the editbox.

The code checks to see if the VTxtAuto control is speaking, in which case the control is told to stop speaking. If the control is not already speaking, either the timer loop is enabled for speaking or the contents of the editbox are spoken.

Private Sub btnSpeak_Click()
If bMonitorClipboard Then
'Speak or stop speaking, depending on state
If oVoice.IsSpeaking Or bTimerLoop Then
'Disable all constraints and redo button caption
bTimerLoop = False
tmrSpeak.Enabled = False
oVoice.StopSpeaking
Else
'Indicate we're speaking and start
tmrSpeak.Enabled = True
End If
Else
'Speak or stop speaking, depending on state
If oVoice.IsSpeaking Then
'Disable all constraint and redo button caption
oVoice.StopSpeaking
Else
'Indicate we're speaking and start SPEAKING
oVoice.Speak txtTextToSpeak, vtxtst_READING
End If
End If
End Sub

The code below is the form initialization and termination code. In the initialization code we create a new instance of the VTxtAuto control, register it, and connect the callback code to the object. In the termination code we stop any outstanding speaking and clean up our resources.

Private Sub Form_Load()
'Get instance of Voice object and register it
Set oVoice = New VTxtAuto.VTxtAuto
oVoice.Register App.Title, App.EXEName
oVoice.Callback = "Speak2Me.VTxtCallback"
'Greet user
oVoice.Speak txtTextToSpeak, vtxtst_READING
'Set for non looping speech
bTimerLoop = False
End Sub
Private Sub Form_Unload(Cancel As Integer)
'Stop any speaking and clean up
If oVoice.IsSpeaking Then
oVoice.StopSpeaking
end If
Set oVoice = Nothing
End Sub

The code below is the timer code. It checks to see if the object is already speaking. If it is, the routine is merely exited. The next step is to compare the existing editbox contents with the contents of the clipboard. If they are the same, the routine is exited.

If the two previous checks pass, then the clipboard contents are stored for future comparisons and the text is spoken via the VTxtAuto object.

Private Sub tmrSpeak_Timer()
Dim sText As String
'Exit if already speaking, to prevent overlap
If oVoice.IsSpeaking Then
Exit Sub
End If
'Get clipboard text and exit if not changed
sText = Clipboard.GetText
If sText = txtTextToSpeak Then
Exit Sub
End If
'Set up text and looping constraint
txtTextToSpeak = sText
bTimerLoop = True
'Speak to user
oVoice.Speak txtTextToSpeak, vtxtst_READING
End Sub

The callback class (VTxtCallback) contained in the file vtxtclbk.cls is the code that the instantiated VTxtAuto object calls when it wants to raise an event. The Visual Basic specification states that code like this must be contained within a class module, and not just an ordinary .bas module. Accordingly, the .cls module contains just the code that is necessary for the two specified events. The following code demonstrates the two events that the VTxtAuto object can interface with.

Option Explicit
Function SpeakingStarted()
frmMain.btnSpeak.Caption = "&Stop"
End Function
Function SpeakingDone()
frmMain.btnSpeak.Caption = "&Speak"
End Function

Conclusion
Performing text-to-speech conversion used to be an expensive and complicated process that most developers were not knowledgeable enough to code. With the Microsoft Speech SDK, and in particular, the Text-to-Speech VTxtAuto ActiveX COM object, this complexity is no longer an issue. With a few simple commands, such as register and speak, any developer can create a TTS-enabled application.

No longer are applications limited to plain old dialog box messages. Now the application can speak to you!
详细请查MSDN: text-to-speech
微软的东西MSDN中都有,老兄要勤查呀
lfd_boy 2002-03-28
  • 打赏
  • 举报
回复
谢谢!
i_jianyong 2002-03-28
  • 打赏
  • 举报
回复
I don't have it, but I am interested in it.
lfd_boy 2002-03-28
  • 打赏
  • 举报
回复
有没有人有呀?????
lfd_boy 2002-03-28
  • 打赏
  • 举报
回复
我忘了说地址了:lfd_boy@263.net

15,446

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 非技术区
社区管理员
  • 非技术区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧