ios - NSNumberFormatter:用 AND 助词拼出一个数字(英式拼写)

标签 ios objective-c nsnumberformatter avspeechsynthesizer

以下代码:

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

导致设备说:“一百 and十二”(英式拼写)

但是,如果您改为音译数字 112:

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

现在 wordNumber 包含“一百十二”(没有和助词)。

所以:

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

如何音译带有助词的数字,即英式拼写?

最佳答案

我相信你需要自己做这件事。我无法产生您想要的结果或找到任何允许我这样做的资源。

我已经链接到一个演示如何手动执行此操作的问题。

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

关于ios - NSNumberFormatter:用 AND 助词拼出一个数字(英式拼写),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22921173/

相关文章:

ios - 使用 Xamarin IOS 在 Visual Studio 中调整 UIView 的大小

ios - Objective-C指针和swift

iphone - 将 double 限制为两位小数,不带尾随零

objective-c - 找出iOS中货币的小数位数

ios - Q - 在 iOS 9 的最新 SDK 中查找与 FBAppCall 等效的类

ios - Swift:在另一个 ViewController 中调用一个函数

ios - UITableView 背景现在随单元格滚动?

ios - Xcode 链接器命令失败 - 找不到目录

ios - iOS 中的 Firebase 性能监控

objective-c - NSNumberFormatter,NSDecimalNumber和科学计数法