4

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?

Community
  • 1
  • 1
Luiz Vaughan
  • 675
  • 1
  • 15
  • 33
  • 2
    What happends if you create you string in a variable and then use it ? – Liora Haydont Feb 14 '18 at 15:14
  • This looks like an odd bug, all 3 should be the same result. Try `Application.Speech.Speak CStr("It is " & "11" & " hours and " & "11" & " minutes")` – Pᴇʜ Feb 14 '18 at 15:21
  • @Pᴇʜ It says the same: "ONE ONE" hours and "eleven" minutes – Luiz Vaughan Feb 14 '18 at 15:53
  • @LuizVaughan That's very strange, I cannot do any further tests because my voice is german and does it correctly. What about if you write it in a variable first `MyText = "It is " & "11" & " hours and " & "11" & " minutes"` and then `Application.Speech.Speak MyText`? Which local (language) version of Office and Windows are you using? – Pᴇʜ Feb 14 '18 at 16:04

3 Answers3

5

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.

Gary's Student
  • 95,722
  • 10
  • 59
  • 99
  • If the OP says the output of `Application.Speech.Speak "It is " & "11" & " hours and " & "11" & " minutes"` is "*ONE ONE hours and ELEVEN minutes*" this answer doesn't help, right? What you say sounds logic and we would expect exactly this (and is exactly what my german voice does). But completely contrary to the effect that the OP described. – Pᴇʜ Feb 14 '18 at 15:55
  • @Pᴇʜ See my **EDIT#1** – Gary's Student Feb 14 '18 at 16:05
  • just for my personal interest did you get the same odd effect of the OP if you speak it directly without concatenating via variable first? – Pᴇʜ Feb 14 '18 at 16:07
  • @Gary's-Student Your answer didn´t work as expected in the Portuguese idiom. In English, it works fine. However, you gave me some insight and I thank you for your time to evaluate this problem. – Luiz Vaughan Feb 14 '18 at 16:19
  • @LuizVaughan Thank YOU for the question! I did not consider *Locale* effects on the code. – Gary's Student Feb 14 '18 at 16:22
  • @Gary'sStudent Just as a contribution to the `Speech.Speak` issue: my approach via **`SpeakXML` argument** seems to override the problem :-) – T.M. Feb 15 '18 at 09:40
  • 1
    @T.M. I will try it today – Gary's Student Feb 15 '18 at 11:50
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.

T.M.
  • 9,436
  • 3
  • 33
  • 57
  • Any links or further information on using the `SpeakXML` setting? (Are there other tags?) – ashleedawg Sep 20 '18 at 20:15
  • 1
    actually I found what I needed [**here**](https://learn.microsoft.com/previous-versions/windows/desktop/ms717077(v=vs.85)) ... I didn't realize the built in TTS was so flexible... – ashleedawg Sep 20 '18 at 20:29
  • @ashleedawg - as it's not so easy to find something about the MS Speech API this SO link might interest you, too [Save SAPI speech to a given file type](https://stackoverflow.com/questions/46285454/vba-save-sapi-speech-to-a-given-file-tye) - *BTW Always appreciate your outstanding helpful hints and answers :-)* – T.M. Sep 21 '18 at 09:16
1

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

Luiz Vaughan
  • 675
  • 1
  • 15
  • 33
  • I would be personally interested if you could try my approach via `SpeakXML` argument and if it showed 2 different spellings. BTW I mentioned a possible local settings issue, too. – T.M. Feb 14 '18 at 16:29
  • 1
    @T.M. As you anticipated, by using the via SpeakXML approach, the words are spelled differently. Firstly "ONE ONE" and then "ELEVEN". – Luiz Vaughan Feb 14 '18 at 16:41
  • Appreciate your fast reply as it confirms my alternative approach. – T.M. Feb 14 '18 at 16:45