设为首页收藏本站Access中国

Office中国论坛/Access中国论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

返回列表 发新帖
查看: 1295|回复: 3
打印 上一主题 下一主题

[Access本身] 请教:如何实现由文本到语音

[复制链接]
跳转到指定楼层
1#
发表于 2008-9-22 20:58:56 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
Word文档中,可以由文本到语音, access的窗体中能实现由文本到语音的功能吗?
如能实现, 请告知实现的过程与代码.
谢谢了!

[ 本帖最后由 wyh99999 于 2008-9-22 21:00 编辑 ]
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享 分享淘帖 订阅订阅
2#
发表于 2008-9-23 01:04:25 | 只看该作者
  1. '===============================================================================
  2. '-函数名称:     MySpeak
  3. '-功能描述:     朗读文本内容
  4. '-输入参数说明: 参数1: 必选 strSpeak As String 朗读的文本内容
  5. '               参数2: 可选 IntRate As Integer  设置朗读的速度 范围:-10到+10
  6. '               参数3: 可选 intVolume As Integer  设置朗读的音量  范围:0到100
  7. '               参数4: 可选 intVoiceID As Integer  朗读者ID
  8. '-返回参数说明:
  9. '-使用语法示例: Call MySpeak ("中华人民共和国")
  10. '-参考:         网上资料
  11. '-使用注意:     需要引用 Microsoft Speech Object Library
  12. '-兼容性:
  13. '-作者:         fan0217@163.com
  14. '-更新日期:    2006-05-25
  15. '===============================================================================
  16. Private Function MySpeak(strSpeak As String, _
  17.                 Optional intRate As Integer = 0, _
  18.                 Optional intVolume As Integer = 50, _
  19.                 Optional intVoiceID As Integer = 0) As Boolean
  20.                
  21. On Error GoTo Err_MySpeak
  22.     Dim oVoise As New SpeechLib.SpVoice
  23.     Dim intTotalSpeech As Integer
  24.    
  25.     intTotalSpeech = oVoise.GetVoices.Count '获取朗读者的数量
  26.    
  27.     If intTotalSpeech = 0 Then Exit Function
  28.    
  29.     '设置朗读者
  30.     If intVoiceID > intTotalSpeech - 1 Then intVoiceID = 0
  31.     Set oVoise.Voice = oVoise.GetVoices.Item(intVoiceID)
  32.    
  33.     '设置朗读速度
  34.     If intRate > 10 Then intRate = 10
  35.     If intRate < -10 Then intRate = -10
  36.         oVoise.Rate = intRate
  37.         
  38.     '设置朗读音量
  39.     If intVolume > 100 Then intVolume = 100
  40.     If intVolume < 0 Then intVolume = 0
  41.         oVoise.Volume = intVolume
  42.         
  43.         oVoise.Speak strSpeak
  44.         
  45.     MySpeak = True
  46.    
  47. Exit_MySpeak:
  48.     Exit Function
  49. Err_MySpeak:
  50.     MySpeak = False
  51.     MsgBox Err.Description, 64, "fan0217"
  52.     Resume Exit_MySpeak
  53. End Function
  54. '===============================================================================
  55. '-函数名称:     GetVoiceIDName
  56. '-功能描述:     获取语音库朗读者名称
  57. '-输入参数说明:
  58. '-返回参数说明:
  59. '-使用语法示例: MsgBox GetVoiceIDName
  60. '-参考:         网上资料
  61. '-使用注意:     需要引用 Microsoft Speech Object Library
  62. '-兼容性:
  63. '-作者:         fan0217@163.com
  64. '-更新日期:    2006-05-25
  65. '===============================================================================
  66. Private Function GetVoiceIDName() As String
  67. Dim oVoise As New SpeechLib.SpVoice
  68. Dim i As Integer
  69. Dim intTotal As Integer
  70. Dim cVoiceIDName As String
  71.     intTotal = oVoise.GetVoices.Count
  72. For i = 0 To intTotal - 1   '遍历语音库
  73.     cVoiceIDName = StrReverse(oVoise.GetVoices.Item(i).ID)
  74.     cVoiceIDName = StrReverse(Left(cVoiceIDName, InStr(cVoiceIDName, "") - 1))
  75.     GetVoiceIDName = GetVoiceIDName + cVoiceIDName + ";"
  76. Next
  77.    
  78.     GetVoiceIDName = Left(GetVoiceIDName, Len(GetVoiceIDName) - 1)
  79.    
  80. End Function
复制代码
示例参考:http://www.office-cn.net/forum.php?mod=viewthread&tid=40497&highlight=%C0%CA%B6%C1

高亮显示代码:
'===============================================================================
'-函数名称:     MySpeak
'-功能描述:     朗读文本内容
'-输入参数说明: 参数1: 必选 strSpeak As String 朗读的文本内容
'               参数2: 可选 IntRate As Integer  设置朗读的速度 范围:-10到+10
'               参数3: 可选 intVolume As Integer  设置朗读的音量  范围:0到100
'               参数4: 可选 intVoiceID As Integer  朗读者ID
'-返回参数说明:
'-使用语法示例: Call MySpeak ("中华人民共和国")
'-参考:         网上资料
'-使用注意:     需要引用 Microsoft Speech Object Library
'-兼容性:
'-作者:         fan0217@163.com
'-更新日期:    2006-05-25
'===============================================================================
Private Function MySpeak(strSpeak As String, _
                Optional intRate As Integer = 0, _
                Optional intVolume As Integer = 50, _
                Optional intVoiceID As Integer = 0) As Boolean
               
On Error GoTo Err_MySpeak
    Dim oVoise As New SpeechLib.SpVoice
    Dim intTotalSpeech As Integer
   
    intTotalSpeech = oVoise.GetVoices.Count '获取朗读者的数量
   
    If intTotalSpeech = 0 Then Exit Function
   
    '设置朗读者
    If intVoiceID > intTotalSpeech - 1 Then intVoiceID = 0
    Set oVoise.Voice = oVoise.GetVoices.Item(intVoiceID)
   
    '设置朗读速度
    If intRate > 10 Then intRate = 10
    If intRate < -10 Then intRate = -10
        oVoise.Rate = intRate
        
    '设置朗读音量
    If intVolume > 100 Then intVolume = 100
    If intVolume < 0 Then intVolume = 0
        oVoise.Volume = intVolume
        
        oVoise.Speak strSpeak
        
    MySpeak = True
   
Exit_MySpeak:
    Exit Function
Err_MySpeak:
    MySpeak = False
    MsgBox Err.Description, 64, "fan0217"
    Resume Exit_MySpeak
End Function
'===============================================================================
'-函数名称:     GetVoiceIDName
'-功能描述:     获取语音库朗读者名称
'-输入参数说明:
'-返回参数说明:
'-使用语法示例: MsgBox GetVoiceIDName
'-参考:         网上资料
'-使用注意:     需要引用 Microsoft Speech Object Library
'-兼容性:
'-作者:         fan0217@163.com
'-更新日期:    2006-05-25
'===============================================================================
Private Function GetVoiceIDName() As String
Dim oVoise As New SpeechLib.SpVoice
Dim i As Integer
Dim intTotal As Integer
Dim cVoiceIDName As String
    intTotal = oVoise.GetVoices.Count
For i = 0 To intTotal - 1   '遍历语音库
    cVoiceIDName = StrReverse(oVoise.GetVoices.Item(i).ID)
    cVoiceIDName = StrReverse(Left(cVoiceIDName, InStr(cVoiceIDName, "\") - 1))
    GetVoiceIDName = GetVoiceIDName + cVoiceIDName + ";"
Next
   
    GetVoiceIDName = Left(GetVoiceIDName, Len(GetVoiceIDName) - 1)
   
End Function


[ 本帖最后由 fan0217 于 2008-9-23 08:13 编辑 ]
3#
发表于 2008-9-23 01:08:41 | 只看该作者
采用Excel朗读功能的朗读器:
注意:需要引用 Microsoft Excel xx.x Object Library


  1. Function MySpeak_Excel(strSpeak As String) As Boolean
  2. On Error GoTo Err_MySpeak_Excel
  3. Dim objEx As New Excel.Application
  4. If IsNull(strSpeak) Then Exit Function

  5. objEx.Speech.Speak strSpeak

  6. MySpeak_Excel = True
  7. Set objEx = Nothing

  8. Exit_MySpeak_Excel:
  9. Exit Function
  10. Err_MySpeak_Excel:
  11. MySpeak_Excel = False
  12. Set objEx = Nothing
  13. MsgBox Err.Description, 64, "fan0217"
  14. Resume Exit_MySpeak_Excel
  15. End Function

复制代码
4#
 楼主| 发表于 2008-9-24 21:55:23 | 只看该作者

回复 2# 的帖子

谢谢您的贴子及回复的内容,并提供了示例的地址。因我是新手,目前无法进入:http://www.office-cn.net/forum.p ... hlight=%C0%CA%B6%C1。所以请您将示例发到我的QQ:496457832
非常感谢!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|站长邮箱|小黑屋|手机版|Office中国/Access中国 ( 粤ICP备10043721号-1 )  

GMT+8, 2024-5-10 18:07 , Processed in 0.099743 second(s), 27 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表