在应用语音 (iOS) 中

  • 本文关键字:iOS 应用 语音 ios
  • 更新时间 :
  • 英文 :


如果我在应用程序中有一个名字列表,我希望人们正确发音他们的名字。我将如何让用户选择名称,然后语音中继如何通过iPhone正确说出它。(例如,Siri语音将"Fred Flintstone"发音给用户,以便他们知道如何以正确的方式说出来)

您可以使用 AVSpeechSynthesizer 类,记录在此处:https://developer.apple.com/library/ios/documentation/AVFoundation/Reference/AVSpeechSynthesizer_Ref/

要让Siri说"Fred Flinstone",你可以这样做:

AVSpeechUtterance *utterance = [AVSpeechUtterance speechUtteranceWithString:@"Fred Flintstone"];
AVSpeechSynthesizer *speechSynthesizer = [[AVSpeechSynthesizer alloc] init];
[speechSynthesizer speakUtterance:utterance];

非常简单和强大!

您还可以通过调整 AVSpeechUtterance 具有的属性来调整 Siri 的声音(请注意,该值需要介于 0 - 1.0 之间):

 utterance.rate = 0.085;
 utterance.pitchMultiplier = 0.85;
 utterance.volume = 0.8;

希望这有帮助。 如果你想要更多细节,我上周写了一篇关于它的博客文章:https://medium.com/@alanscarpa/how-to-use-avspeechsynthesizer-to-make-your-app-talk-d07f424689b0

最新更新