AVF 1 - tts

AVF 1 - tts


一、简介

相关类

  • AVSpeechSynthesizer // 用语音播放一段文字
  • AVSpeechUtterance // 包裹一段需要播放的文字
  • AVSpeechSynthesisVoice

二、使用

1、播放语音

- (void)test1{
        
    AVSpeechSynthesizer *synthesizer = [[AVSpeechSynthesizer alloc] init];
    
    NSString *speechStrings = @"Hello AV Foundation. How are you?";
    
    AVSpeechUtterance *utterance = [[AVSpeechUtterance alloc] initWithString:speechStrings];
    
    AVSpeechSynthesisVoice *voice = [AVSpeechSynthesisVoice voiceWithLanguage:@"en-US"];
    
    utterance.voice = voice;  // 设置使用哪一个国家的语言播放
    utterance.rate = 0.5f; // 本段文字播放时的 语速, 应介于AVSpeechUtteranceMinimumSpeechRate 和 AVSpeechUtteranceMaximumSpeechRate 之间
    utterance.pitchMultiplier = 0.8f;   // 在播放特定语句时改变声音的声调, 一般取值介于0.5(底音调)~2.0(高音调)之间
    utterance.postUtteranceDelay = 0.1f;
    
    [synthesizer speakUtterance:utterance];
    
}

2、获得所有国家语言

[AVSpeechSynthesisVoice speechVoices] 打印出支持的所有国家语言

发布了43 篇原创文章 · 获赞 8 · 访问量 4567

猜你喜欢

转载自blog.csdn.net/weixin_45390999/article/details/104555908
TTS