【发布时间】:2014-02-09 23:45:04
【问题描述】:
我使用以下代码使用按钮初始化文本到语音合成。但有时用户可能希望在语音中间停止声音。我可以知道是否有任何代码可以做到这一点。
谢谢
这是我的代码
@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
【问题讨论】:
标签: ios iphone objective-c ios7 text-to-speech