Ios 如何在文本到语音合成过程中停止语音?
我使用以下代码使用按钮初始化文本到语音合成。但有时用户可能希望在演讲的中间停止声音。我可以知道有什么代码可以帮你吗 谢谢 这是我的密码Ios 如何在文本到语音合成过程中停止语音?,ios,iphone,objective-c,ios7,text-to-speech,Ios,Iphone,Objective C,Ios7,Text To Speech,我使用以下代码使用按钮初始化文本到语音合成。但有时用户可能希望在演讲的中间停止声音。我可以知道有什么代码可以帮你吗 谢谢 这是我的密码 @interface RMDemoStepViewController () @end @implementation RMDemoStepViewController - (void)viewDidLoad { [super viewDidLoad]; //Add Border to TextBox //Instantiate
@interface RMDemoStepViewController ()
@end
@implementation RMDemoStepViewController
- (void)viewDidLoad
{
[super viewDidLoad];
//Add Border to TextBox
//Instantiate the object that will allow us to use text to speech
self.speechSynthesizer = [[AVSpeechSynthesizer alloc] init];
[self.speechSynthesizer setDelegate:self];
}
- (IBAction)speakButtonWasPressed:(id)sender{
[self speakText:[self.textView text]];
}
- (void)speakText:(NSString *)toBeSpoken{
AVSpeechUtterance *utt = [AVSpeechUtterance speechUtteranceWithString:toBeSpoken];
utt.rate = [self.speedSlider value];
[self.speechSynthesizer speakUtterance:utt];
}
- (IBAction)speechSpeedShouldChange:(id)sender
{
UISlider *slider = (UISlider *)sender;
NSInteger val = lround(slider.value);
NSLog(@"%@",[NSString stringWithFormat:@"%ld",(long)val]);
}
@end
<>但是有时用户可能想在演讲的中间停止声音。< /P>
要停止语音,请向语音合成器发送消息:
如果希望语音继续到当前单词的结尾而不是立即停止,请使用AVSpeechBoundaryWord
而不是AVSpeechBoundaryImmediate
您也可以不完全停止它。这将完全停止语音合成器:
-stopspeakingaboundary
,如果您想在SS后面添加更多代码,请将:
放在末尾。因此基本上,-stopspeakingaboundary:
为了让完整的代码与您的代码相匹配,这里:[self.speechSynthesizer stopspeakingaboundary:avspeechboundaryimediate]代码>
[self.speechSynthesizer stopSpeakingAtBoundary:AVSpeechBoundaryImmediate];