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

后端 未结 3 963
日久生厌
日久生厌 2021-01-13 17:24

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(No         


        
相关标签:
3条回答
  • 2021-01-13 17:50

    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.

    0 讨论(0)
  • 2021-01-13 18:02

    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.

    0 讨论(0)
  • 2021-01-13 18:05

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

    0 讨论(0)
提交回复
热议问题