0

Today I stumbled upon a very curious behaviour of iOS's AVSpeechSynthesizer. If I give it a string containing "DON 21" using the German language, it'll say "Donnerstag, 21.". (It will automatically translate "THU 21" to "Thursday 21st" and read this string. Unfortunately I need to read the text provided by another source that may or may not contain strings like "DON 21" or others (depending on the language). Has anyone ever encountered this behavior? Does anyone know how to turn the automatic date transscription off?

matt
  • 515,959
  • 87
  • 875
  • 1,141
Geru
  • 624
  • 1
  • 7
  • 20

1 Answers1

2

Try deleting the space or adding other punctuation: it might pronounce "DON21" differently. If that doesn't work, use attributedSpeechString to tell the synthesizer to pronounce this part of the string the way you want it pronounced.

matt
  • 515,959
  • 87
  • 875
  • 1,141
  • Thanks for hte quick response. Apparently I need to reframe the question then: Which attributes would I have to set so that "THU 21" does not get expanded to "Thursday twenty first" as I'd like to have the synthesizer say "T" "H" "U" "twenty one"? – Geru Feb 25 '19 at 16:50
  • And my answer says what to do. If you see "THU 21", use the attributed speech string to make the pronunciation of that phrase be "tee aitch you twenty one". – matt Feb 25 '19 at 17:01
  • Another possibility might be to remove the space, i.e. make it "THU21". It might pronounce that the way you desire, without any further changes. You'll have to experiment. But either way it's the same principle: if you don't like the pronunciation of the string, change the string and/or add the attributed speech string to dictate the pronunciation. – matt Feb 25 '19 at 17:02
  • turns out that it doesn't care for white space characters, but apparently underscores do the trick – Geru Feb 25 '19 at 17:04
  • @matt: how do you use the "attributedSpeechString" instance property that is only a getter, please ? If you need to specify something to the synthesizer, it must be a setter as well, mustn't it ? – XLE_22 May 13 '19 at 10:52
  • 1
    @XLE_22 https://developer.apple.com/documentation/avfoundation/avspeechutterance/1648776-init – matt May 13 '19 at 18:11