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];

            

        }

        

    }

  • 相关阅读:
    关于Action中ValidateXXX方法校验一次失败后\导致以后一直返回input视图的情况
    but has failed to stop it. This is very likely to create a memory leak(c3p0在Spring管理中,连接未关闭导致的内存溢出)
    个人学习笔记MyBatis的搭建及第一个程序
    Hibernate学习笔记环境搭建及运行
    个人学习笔记MyBatis官方推荐DAO开发方案
    个人笔记struts2对Action的权限拦截
    hession
    正向代理,反向代理
    path,classpath
    session
  • 原文地址:https://www.cnblogs.com/daxueshan/p/7449684.html
Copyright © 2011-2022 走看看