Why does Application.Speech.Speak read some number

2019-02-18 07:54发布

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?

3条回答
Fickle 薄情
2楼-- · 2019-02-18 08:35

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楼-- · 2019-02-18 08:35

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 :)

查看更多
叼着烟拽天下
4楼-- · 2019-02-18 08:37

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.

查看更多
登录 后发表回答