我为 phonegap 制作了一个插件,允许用户听到一段文本,AVSpeechSynthesizer
但我似乎无法pauseSpeakingAtBoundary
正常工作。
出于测试目的,它当前接收要合成的文本字符串或显示“暂停”的字符串,并仅检查 i f (![echo isEqual:@'PAUSE']
) 以确定是否应该尝试暂停话语。讲话开始,并在收到“暂停”但合成器继续讲话时记录下来。
我对此完全陌生,所以我不确定我是否犯了错误或pauseSpeakingAtBoudary
. 我的代码如下。谢谢。
重申一下,这是我无法开始工作的 pauseSpeakingAtBoundary。根据 phonegaps 文档,语音合成是通过 javascript 执行程序工作的。
//
// Echo.h
// Plugin
//
//
//
//
#import <Cordova/CDVPlugin.h>
#import <AVFoundation/AVFoundation.h>
@interface Echo : CDVPlugin <AVSpeechSynthesizerDelegate>
@property (strong, nonatomic) AVSpeechSynthesizer *synthesizer;
- (void) echo:(NSMutableArray*)arguments;
@end
//
// Echo.m
// Plugin
//
//
//
//
#import "Echo.h"
@implementation Echo
- (void)echo:(CDVInvokedUrlCommand*)command
{
CDVPluginResult* pluginResult = nil;
NSString* echo = [command.arguments objectAtIndex:0];
AVSpeechSynthesizer *synthesizer = [[AVSpeechSynthesizer alloc] init];
synthesizer.delegate = self;
if (echo != nil && [echo length] > 0 ) {
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:echo];
if( ![echo isEqual:@"PAUSE"]) {
AVSpeechUtterance *utterance = [[AVSpeechUtterance alloc] initWithString:echo];
utterance.rate = 0.20;
utterance.voice = [AVSpeechSynthesisVoice voiceWithLanguage:@"en-gb"];
[synthesizer speakUtterance:utterance];
} else {
NSLog(@"Pausing");
[synthesizer pauseSpeakingAtBoundary:AVSpeechBoundaryImmediate];
}
} else {
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
}
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}
@end