• 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);
    }
  • 相关阅读:
    《XXX重大技术需求征集系统》的可用性和可修改性战术分析
    淘宝网的软件质量属性分析
    软件架构师如何工作
    PHP 运算符
    PHP函数
    PHP自定义函数
    Mysql 允许外连
    PHP 小练习题持续更新
    文本文件编辑命令
    工作目录切换命令、打包压缩文件命令
  • 原文地址:https://www.cnblogs.com/codemakerhj/p/6037993.html
Copyright © 2020-2023  润新知