Why does Application.Speech.Speak read some numbers individually rather than put them together?

风格不统一 提交于 2019-12-30 10:08:06

问题


Let's suppose now it is 11h11min. It reads "ONE ONE" hours and "eleven" minutes, as in:

Sub TEST1() 
  Application.Speech.Speak "It is " & Hour(Now()) & " hours and " & Minute(Now()) & " minutes"
End Sub

However, the following reads "eleven" hours and "eleven" minutes

Sub TEST2() 
  Application.Speech.Speak "It is 11 hours and 11 minutes"
End Sub

On the contrary, it reads "ONE ONE" hours and "eleven" minutes, as in:

Sub TEST3() 
  Application.Speech.Speak "It is " & "11" & " hours and " & "11" & " minutes"
End Sub

How can I get it to read these numbers as words?


回答1:


You need to create/modify the string to produce the results you want.

Sub dural()
    Application.Speech.Speak "11"
    Application.Speech.Speak "eleven"
End Sub

will repeat the same thing.

Sub dural()
    Application.Speech.Speak "1 1"
    Application.Speech.Speak "one one"
End Sub

will do the same. Once you have decided what you want the computer to say, you can format/re-format the string to produce that result.

EDIT#1:

On my computer this:

Sub dmral()
    Dim s As String
    s = "It is " & "11" & " hours and " & "11" & " minutes"
    MsgBox s
    Application.Speech.Speak s
End Sub

also works as expected.

It looks like the concatenation needs to be performed first.




回答2:


Approach via SpeakXML argument

Syntax

.Speak(Text, SpeakAsync, SpeakXML, Purge)

If you set the 3rd argument SpeakXML to True, you can use XML tags in your text string.

The XML <spell> tag forces the voice to spell out all text, rather than using its default word and sentence breaking rules. All characters should be expanded to corresponding words (including punctuation, numbers, and so forth). Note that the <spell> tag mustn't be empty and don't forget the closing tag </spell>.

Try to use the following with both variants of 11:

Code

Sub TEST()
  Application.Speech.Speak "It is " & "<spell>11</spell>" & " hours and " & "11" & " minutes", False, SpeakXML:=True
End Sub

Note/caveat

I'm using a central European language Version and your example did'nt speak out ONE ONE in my case, so maybe there is another local setting issue.




回答3:


The Portuguese language has some interesting pronunciation challenges. We have, among other, the nasal "-ão" termination for words as in São Paulo. The -ão is pronounced almost like the -ow in "sow" and it means that while you pronounce the vowels, the air should come out partly from your nose. That being said ...

Application.Speech.Speak "Já são" & Hour(Now()) & "horas e 11 minutos" --> reads "It is ONE ONE hours and ELEVEN minutes"

Application.Speech.Speak "11" --> reads "ELEVEN"

Application.Speech.Speak "Já são" & "11" & "horas" --> reads "It is ONE ONE hours"

Application.Speech.Speak "Já sao" & Hour(Now()) --> reads "It is ELEVEN hours". Notice that the nasal -"ão" was removed in this case. So, the number pronunciation is in words

Application.Speech.Speak "Já são^" & Hour(Now()) --> reads "It is ELEVEN hours". Notice that the nasal -"ão" is now present and also there is a "^" sign positioned just afterwards

I don´t know why Excel behaves like that. But, problem solved :)



来源:https://stackoverflow.com/questions/48790329/why-does-application-speech-speak-read-some-numbers-individually-rather-than-put

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!