现在使用PB开发一个语音朗读软件, XP系统语音引擎有Microsoft Mary(女声), Microsoft Sam(男声) . 要指定使用其中一个声音. 但不知在PB下如何设置函数 tts.setvoice() 的参数?
附 源程序
1、先声明实例变量
oleobject tts
2、窗口打开时,实例化变量
//调用SAPI语音,前提已装好SAPI
long ll_status
tts = CREATE OLEObject
ll_status = tts.ConnectToNewObject("SAPI.SpVoice")
IF ll_status <> 0 THEN
messagebox('调用错误','您可能还未安装语音库!')
tts.DisconnectObject()
DESTROY tts
else
wf_ini()
end if
//其中,Wf_ini为窗口函数
/取得当前安装的语音引擎和输出的音频设备
//注意,像VB等语言,数组下标以'0'开始
//返回1,正常;返回0,取得引擎失败;返回-1,取得音频设备失败(可能未安装声卡)
integer n,m
string ls_desp
//取得引擎列表
m = integer(tts.GetVoices.Count)
if m < 1 then return 0
for n=1 to m
ls_desp = string(tts.GetVoices.Item[n - 1].GetDescription())
if n=1 then ddlb_voice.text = ls_desp
ddlb_voice.additem(ls_desp)
next
//取得音频输出列表
m = tts.GetAudioOutputs.count
if m < 1 then return -1
for n=1 to m
ls_desp =string(tts.GetAudioOutputs.Item[n - 1].GetDescription())
if n=1 then ddlb_audio_out.text = ls_desp
ddlb_audio_out.additem(ls_desp)
next
return 1
tts.setvocie( ????? )
3、朗读
string ls_read
integer li_ret
//终止先前朗读,如果有
li_ret = tts.speak(" ","2")
//异步朗读
li_ret = tts.speak(mle_read.text,"1")
------解决方案--------------------
楼主是否应该从ddlb_voice中得到 引擎index
然后设置
tts.voice=tts.GetVoices.item(index -1)
执行 tts.speak(context,11)
即可
------解决方案--------------------
楼上正解
tts.voice=tts.GetVoices.item(index -1)
来设置语音引擎
Voice Property
The Voice property specifies the SpVoice object associated with the recognition context.
Syntax
Set: SpeechRecoContext.Voice = SpVoice