zoukankan      html  css  js  c++  java
  • 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);
    }
  • 相关阅读:
    Bootstrap入门
    CSS3动画详解(图文教程)
    CSS3属性详解(图文教程)
    CSS3选择器详解
    HTML5详解
    jQuery动画详解
    jQuery的介绍和选择器详解
    html 出现粒子线条,鼠标移动会以鼠标为中心吸附的特效之canvas-nest.js插件
    div 内容宽度自适应、超出后换行
    layui layui.open弹窗后按enter键不停弹窗问题的解决
  • 原文地址:https://www.cnblogs.com/codemakerhj/p/6037993.html
Copyright © 2011-2022 走看看