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

            

        }

        

    }

  • 相关阅读:
    使用C#调用C++类库
    C# IntPtr类型
    C# 调用C++ dll string类型返回
    C# try、catch、finally语句
    C语言 char *、char []、const char *、string的区别与相互转换
    C# 字符串string与char数组互转!
    C#如何调用C++(进阶篇)
    Springboot通过过滤器实现对请求头的修改
    【spring事务】
    命令行参数库:McMaster.Extensions.CommandLineUtils【转】
  • 原文地址:https://www.cnblogs.com/daxueshan/p/7449684.html
Copyright © 2011-2022 走看看