zoukankan      html  css  js  c++  java
  • AVFoundation 文本语音播报

     

    #import <Foundation/Foundation.h>

    #import <AVFoundation/AVFoundation.h>

     

    @interface Speaker : NSObject

     

    @property(nonatomic,strong)AVSpeechSynthesizer *synthesizer;

     

    + (instancetype)speechcontroller;

     

    - (void)beginConversation;

     

    @end

     

    ///

    #import "Speaker.h"

     

    @interface Speaker ()

     

    @property(nonatomic,strong)NSArray *voices;

    @property(nonatomic,strong)NSArray *speechStrings;

     

    @end

     

    @implementation Speaker

     

     

    + (instancetype)speechcontroller{

        return [[self alloc]init];

    }

    - (instancetype)init

    {

        self = [super init];

        if (self) {

            _synthesizer = [[AVSpeechSynthesizer alloc]init];

            

          //zh-CN 中文  en-US 英文

            _voices = @[[AVSpeechSynthesisVoice voiceWithLanguage:@"zh-CN"],

    //                    [AVSpeechSynthesisVoice voiceWithLanguage:@"en-GB"]

                        ];

            

            _speechStrings = @[@"hello world",

                               @"文本播报",

                               @"very good"

                               ];

        }

        return self;

    }

     

     

     

    - (void)beginConversation{

        for (int i = 0; i<self.speechStrings.count; i++) {

            AVSpeechUtterance *utterance = [[AVSpeechUtterance alloc]initWithString:self.speechStrings[i]];

            utterance.voice = self.voices[0];//设置声音

            utterance.rate = 0.4f;//播放语音内容的速度

            utterance.pitchMultiplier = 0.7f;//语调

            utterance.postUtteranceDelay = 0.1f;//在说下一句话前的停顿时长

            //开始语音播放

            [self.synthesizer speakUtterance:utterance];

            

        }

        

    }

  • 相关阅读:
    Block定制开发小记
    三个方法解决error: use of moved value
    Rust踩坑日记
    动态竞争
    求数组差/交集函数-php数组函数(二)
    深度完整的了解MySQL锁
    PHP 结合前端 ajax 爬取网站信息后, 向指定用户发送指定短信;
    Nginx配置 隐藏入口文件index.php
    如何用纯 CSS 创作一个按钮文字滑动特效
    Laravel学习:请求到响应的生命周期
  • 原文地址:https://www.cnblogs.com/daxueshan/p/7449684.html
Copyright © 2011-2022 走看看