iOS 语音朗读

//判断版本大于7.0
    if ([[[UIDevice currentDevice] systemVersion] integerValue] >= 7.0) {
        NSString * tempStr = @"朗读内容! ";
        AVSpeechUtterance * utterance = [AVSpeechUtterance speechUtteranceWithString:[NSString stringWithFormat:@"话秋天气提醒您:%@", tempStr]];
        //速率
        utterance.rate = 0.15;
        //设置语言
        utterance.voice = [AVSpeechSynthesisVoice voiceWithLanguage:@"zh-CN"];
        AVSpeechSynthesizer * synthesizer = [[AVSpeechSynthesizer alloc] init];
        //获取当前系统语音 - 语音合成器会生成音频
        [synthesizer speakUtterance:utterance];
    }else {
        UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:@"当前系统不支持语音播报" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil];
        [alertView show];
    }

posted on 2016-12-16 15:40  雨季的雾  阅读(212)  评论(0编辑  收藏  举报