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);
    }
  • 相关阅读:
    Flask安装教程
    Django进阶(2)
    反编译源码
    Jmeter之Bean shell使用(一)
    接口测试基础(fiddler、postman的使用、python实现测试接口程序)
    Fiddler显示服务器IP的方法
    web测试与app测试的区别
    互联网产品接入支付功能如何测试?
    web测试中的测试点和测试方法总结
    使用JMeter建立接口测试
  • 原文地址:https://www.cnblogs.com/codemakerhj/p/6037993.html
Copyright © 2011-2022 走看看