2014-11-25 106 views
1

有沒有什麼辦法可以創建VBA代碼來通過音頻讀取文檔?就好像電腦正在讀取文件上的內容一樣。 (當然是全部文字)。VBA代碼讀取文檔文檔

+0

這就是第三方軟件[Dragon Natural lySpeaking](https://en.wikipedia.org/wiki/Dragon_NaturallySpeaking)。分享你的研究有助於每個人告訴我們你試過了什麼,以及它爲什麼不符合你的需求。這表明你已經花時間去嘗試幫助自己,它使我們避免重申明顯的答案,最重要的是它可以幫助你得到更具體和相關的答案!另請參見[如何問](http://stackoverflow.com/help/how-to-ask) – 2014-11-25 14:39:51

+0

感謝Scott - 我還沒有嘗試過任何東西,因爲我不知道VBA是否可以實現。謝謝 – GeekZinside 2014-11-25 14:55:59

回答

1

我在google上發現了這個搜索。 http://vbadud.blogspot.com/2010/06/vba-how-to-convert-text-file-to-speech.html

Sub Speech_FromFile_Example() 

    Dim oVoice As SpVoice 
    Voice Object Dim oVoiceFile As SpFileStream 
    File Stream Object Dim sFile As String 
    File Name Set oVoice = New SpVoice 
    Set oVoiceFile = New SpFileStream 


    oVoice.Speak "This is an example for reading out a file" 
    sFile = "C:\ShasurData\ForBlogger\SpeechSample.txt" 
    oVoiceFile.Open sFile 
    oVoice.SpeakStream oVoiceFile 

End Sub 

代碼要求微軟語音對象庫

VBA宏字:

Dim speech as SpVoice 

Sub SpeakText() 

On Error Resume Next 

Set speech = New SpVoice 

If Len(Selection.Text) > 1 Then 'speak selection 
speech.Speak Selection.Text 



SVSFlagsAsync + SVSFPurgeBeforeSpeak 



Else 'speak whole document 
speech.Speak ActiveDocument.Range(0, ActiveDocument.Characters.Count).Text 



SVSFlagsAsync + SVSFPurgeBeforeSpeak 



End If 

Do 
DoEvents 

Loop Until speech.WaitUntilDone(10) 

Set speech = Nothing 

End Sub 

Sub StopSpeaking() 

'Based on a macro by Mathew Heikkila 

'used to interrupt any running speech to text 

On Error Resume Next 

speech.Speak vbNullString, SVSFPurgeBeforeSpeak 

Set speech = Nothing 

End Sub 
+0

謝謝,我會嘗試這個並回復。 – GeekZinside 2014-11-25 17:29:50

+0

@幸運之後? – GlobalJim 2014-11-26 13:20:53

+0

對不起,延遲迴復 - 它沒有工作。我沒有收到任何錯誤消息或任何音頻。我會繼續尋找並分享我的發現。 – GeekZinside 2015-01-07 15:20:35

0

要小心,如果你使用的是Windows 10 - 我有兩個庫具有相同的名稱「微軟語音對象庫「 - 確保你選擇了一個指向Windows/system32/Speech/Common/sapi.dll的文件。