可可:言语和时间
我正在构建一个应用程序,其中一部分会说出时间。但是,当我将日期字符串(如 10/24/11)传递给 NSSpeechSynthesizer 时,它会按字面意思发音,如“一、零、斜线二四斜线一一”,与时间戳相同,“八冒号一一”冒号冒号”等。
我查看了 NSSpeechSynthesizer 文档,我想我必须使用phonemesFromText 方法,但这似乎需要大量繁重的工作才能获得该应用程序顺利说出时间和日期。有没有更快的方法?
谢谢
I'm building an app that a part of will speak the time. However, when I pass in my date strings (like 10/24/11) to the NSSpeechSynthesizer it will speak them literally, as "one, zero, slash two four slash one one", same with a timestamp, "eight colon one one colon colon", etc. etc.
I looked at the NSSpeechSynthesizer docs and I guess I'd have to work with the phonemesFromText method but that seems like a lot of grunt work to get the app to speak the time and date smoothly. Is there a quicker method?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以尝试这样的操作:
基本上,这是使用 2 个 NSDateFormatter:一个将日期的字符串表示形式“翻译”为实际的 NSDate 对象,然后另一个将
NSDate
转换回更理想的字符串表示形式。显然,您需要调整
dateParser
格式以适合您预期的输入字符串类型。 (最好,您可以只使用输入日期而不是它的字符串表示形式)。You could try something like this:
Basically, this is using 2
NSDateFormatter
s: one to "translate" the string representation of a date into an actualNSDate
object, and then another to translate thatNSDate
back into a more desirable string representation.Obviously, you'll need to adjust the
dateParser
format to fit your expected input string type. (Preferably, you could just use an input date rather than the string representation of it).为什么不使用 NSDateComponents to 和 -[NSString stringWithFormat:] 构建一个口语句子作为您的字符串,然后说出那个?
Why not use NSDateComponents to and -[NSString stringWithFormat:] construct a spoken sentence as your string, then speak that?