iOSでの音声ブロードキャスト

最近、インターネットで「アリペイが100万元を受け取った」のリングトーンはとても?

iOS7.0以降、いくつかの新しい機能が追加され、システム独自の音声ブロードキャストライブラリがあり、システムのAVFoundationライブラリにインポートする必要があります。

#import "ViewController.h"

#import <AVFoundation/AVFoundation.h>

@interface ViewController ()<AVSpeechSynthesizerDelegate>

/** 播报的内容 */
@property (nonatomic, readwrite , strong) AVSpeechSynthesizer *synth;
/** 负责播放 */
@property (nonatomic, readwrite , strong) AVSpeechUtterance *utterance;

@end

基本的な使い方

NSString *str = @"支付宝 到账 100万 元";
self.utterance = [AVSpeechUtterance speechUtteranceWithString:str];//成功集成语音播报
	
		//pitchMultiplier: 音高
		//
		//postUtteranceDelay: 读完一段后的停顿时间
		//
		//preUtteranceDelay: 读一段话之前的停顿
		//rate: 读地速度, 系统提供了三个速度: AVSpeechUtteranceMinimumSpeechRate, AVSpeechUtteranceMaximumSpeechRate, AVSpeechUtteranceDefaultSpeechRate
	self.utterance.rate = AVSpeechUtteranceDefaultSpeechRate;// 播报的语速
	
		//	中式发音
	AVSpeechSynthesisVoice *voice = [AVSpeechSynthesisVoice voiceWithLanguage:@"zh-CN"];
		//英式发音
		//	AVSpeechSynthesisVoice *voice = [AVSpeechSynthesisVoice voiceWithLanguage:@"en-GB"];
	
	self.utterance.voice = voice;
	
	self.synth = [[AVSpeechSynthesizer alloc] init];
	self.synth.delegate = self;// 设置代理
	[self.synth speakUtterance:self.utterance];

 

プロキシ方式

//已经开始
- (void)speechSynthesizer:(AVSpeechSynthesizer *)synthesizer didStartSpeechUtterance:(AVSpeechUtterance *)utterance API_AVAILABLE(ios(7.0), watchos(1.0), tvos(7.0), macos(10.14)) {
	
}
//已经说完
- (void)speechSynthesizer:(AVSpeechSynthesizer *)synthesizer didFinishSpeechUtterance:(AVSpeechUtterance *)utterance API_AVAILABLE(ios(7.0), watchos(1.0), tvos(7.0), macos(10.14)) {

}
//已经暂停
- (void)speechSynthesizer:(AVSpeechSynthesizer *)synthesizer didPauseSpeechUtterance:(AVSpeechUtterance *)utterance API_AVAILABLE(ios(7.0), watchos(1.0), tvos(7.0), macos(10.14)) {

}
//已经继续说话
- (void)speechSynthesizer:(AVSpeechSynthesizer *)synthesizer didContinueSpeechUtterance:(AVSpeechUtterance *)utterance API_AVAILABLE(ios(7.0), watchos(1.0), tvos(7.0), macos(10.14)) {

}
//已经取消说话
- (void)speechSynthesizer:(AVSpeechSynthesizer *)synthesizer didCancelSpeechUtterance:(AVSpeechUtterance *)utterance API_AVAILABLE(ios(7.0), watchos(1.0), tvos(7.0), macos(10.14)) {

}
//将要说某段话
- (void)speechSynthesizer:(AVSpeechSynthesizer *)synthesizer willSpeakRangeOfSpeechString:(NSRange)characterRange utterance:(AVSpeechUtterance *)utterance API_AVAILABLE(ios(7.0), watchos(1.0), tvos(7.0), macos(10.14)) {

}

 

おすすめ

転載: blog.csdn.net/zjpjay/article/details/92840463
おすすめ