Frage

The following code:

AVSpeechSynthesizer * speechSynthesizer = [[AVSpeechSynthesizer alloc] init];
AVSpeechUtterance *utterance = [AVSpeechUtterance speechUtteranceWithString: @"112"];
utterance.voice = [AVSpeechSynthesisVoice voiceWithLanguage:@"en-GB"];
speechSynthesizer  speakUtterance:utterance];

results in with the device saying: "one hundred and twelve" (British spelling)

But if instead you transliterate the number 112:

NSString * wordNumber = nil;
NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
[numberFormatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en-GB"]];
[numberFormatter setNumberStyle:NSNumberFormatterSpellOutStyle];
wordNumber = [numberFormatter stringFromNumber:@(112)];

now wordNumber contains "one hundred twelve" (without the and particle).

So:

@"112" -> AVSpeechSynthesizer -> "one hundred and twelve"
@"112" -> NSNumberFormatter   -> "one hundred twelve"

How can I transliterate a number with the and particles,i.e, British spelling?

War es hilfreich?

Lösung

I believe you'll need to do this yourself. I haven't been able to produce your desired result or find any resource that allows me to do so.

I've linked to a question that demonstrates how to do this manually.

Is it possible to spell out numbers in words with a separator?

Andere Tipps

Huh, can't you just do this?

AVSpeechUtterance *utterance = [AVSpeechUtterance speechUtteranceWithString:@"112"];
utterance.voice = [AVSpeechSynthesisVoice voiceWithLanguage:@"en-GB"];
NSString *transliteration = utterance.speechString;
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top