iOS Swift:UIAccessibilitySpeechAttributeIPANotation

编程入门 行业动态 更新时间:2024-10-26 14:40:45
本文介绍了iOS Swift:UIAccessibilitySpeechAttributeIPANotation的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试使我的应用使用AVSpeechSynthesizer在IPANotation中讲话,但是下面的代码段不起作用

I am trying to make my app to speak in the IPANotation using AVSpeechSynthesizer, but it not working below is my code snippet,

let synthesizer = AVSpeechSynthesizer() let attributedStr = NSMutableAttributedString(string: "Hello iPhone") attributedStr.addAttribute(NSAttributedString.Key(UIAccessibilitySpeechAttributeIPANotation), value: "ˈa͡ɪ.ˈfo͡ʊn", range: NSRange(location: 6, length: 6)) let utterance = AVSpeechUtterance(attributedString: attributedString) synthesizer.speak(utterence)

谢谢

推荐答案

在此之后尝试代码段(iOS 12-Swift 5.0):

let attrStr = NSMutableAttributedString(string: "hello my little ") let pronunciationKey = NSAttributedString.Key(rawValue: AVSpeechSynthesisIPANotationAttribute) let attrStr2 = NSMutableAttributedString(string: "blablabla", attributes: [pronunciationKey: "ˈa͡ɪ.ˈfo͡ʊn"]) let finalAttrStr = NSMutableAttributedString() finalAttrStr.append(attrStr) finalAttrStr.append(attrStr2) let utterance = AVSpeechUtterance(attributedString: finalAttrStr) utterance.voice = AVSpeechSynthesisVoice(language: "en-GB") let synthesizer = AVSpeechSynthesizer() synthesizer.speak(utterance)

这不是完美的方法,但它使使用 AVSpeechSynthesizer .

This is not perfect but it makes the IPA notation work using AVSpeechSynthesizer.

还可以提供另一个示例了解如何获取音素并将其放入代码中.

Another example is also available to figure out how to get the phonemes and put them into the code.

更多推荐

iOS Swift:UIAccessibilitySpeechAttributeIPANotation

本文发布于:2023-08-05 17:05:30,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1306844.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:iOS   Swift   UIAccessibilitySpeechAttributeIPANotation

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!