ios 播放语音(文字转语音) 播放音频文件 振动
#pragma mark - 播放语音 -(void)play:(NSString *)word { // AVSpeechSynthesisVoice *voice = [AVSpeechSynthesisVoice voiceWithLanguage:@"zh-HK"]; AVSpeechSynthesisVoice *voice = [AVSpeechSynthesisVoice voiceWithLanguage:@"zh-CN"]; // AVSpeechSynthesisVoice *voice = [AVSpeechSynthesisVoice voiceWithLanguage:@"zh-TW"]; AVSpeechUtterance *utterance = [AVSpeechUtterance speechUtteranceWithString:word]; utterance.voice = voice; if (BCAvalibleOS(9.0)) { utterance.rate = 0.5; } else { utterance.rate = 0.1; } utterance.volume = 1.0; AVSpeechSynthesizer *syntheSizer = [[AVSpeechSynthesizer alloc]init]; syntheSizer.delegate = self; [syntheSizer speakUtterance:utterance]; } #pragma mark - 播放音频文件 -(void)playSound { NSLog(@"播放音频文件"); NSString *path = [[NSBundle mainBundle] pathForResource:@"test2" ofType:@"wav"]; if (path) { //注册声音到系统 AudioServicesCreateSystemSoundID((__bridge CFURLRef)[NSURL fileURLWithPath:path],&shake_sound_male_id); AudioServicesPlaySystemSound(shake_sound_male_id); // AudioServicesPlaySystemSound(shake_sound_male_id);//如果无法再下面播放,可以尝试在此播放 } AudioServicesPlaySystemSound(shake_sound_male_id); //播放注册的声音,(此句代码,可以在本类中的任意位置调用,不限于本方法中) // AudioServicesPlaySystemSound(kSystemSoundID_Vibrate); //让手机震动 } #pragma mark - 振动 - (void)vibrate { NSLog(@"振动"); AudioServicesPlaySystemSound(kSystemSoundID_Vibrate); }
posted on 2016-11-07 11:06 codemaker313 阅读(358) 评论(0) 编辑 收藏 举报