2
我做了一個手機插件,允許用戶聽到使用AVSpeechSynthesizer
一段文字,但我似乎無法讓pauseSpeakingAtBoundary
工作。IOS手機AVSpeechSynthesizer插件pauseSpeakingAtBoundary不工作
出於測試目的,它目前接收到一個要合成的文本字符串或一個字符串,說'暫停',只是檢查我確定它是否應該嘗試暫停話語。講話開始並在收到「暫停」時記錄,但合成器繼續講話。
我對此完全陌生,因此我不確定自己是否犯了錯誤或者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