用于phonegap pauseSpeakingAtBoundary的ios AVSpeechSynthesizer插件不起作用
<p><p>我为 phonegap 制作了一个插件,允许用户使用 <code>AVSpeechSynthesizer</code> 听到一段文本,但我似乎无法让 <code>pauseSpeakingAtBoundary</code> 工作。</code> p>
<p>出于测试目的,它当前接收要合成的文本字符串或显示“PAUSE”的字符串,并仅检查 i<code>f (!</code>) 以确定它是否应该尝试暂停话语。讲话开始并在收到“PAUSE”时记录下来,但
合成器继续说话。</p>
<p>我对此完全陌生,所以我不确定我是否犯了错误或 <code>pauseSpeakingAtBoudary</code> 有问题。
我的代码如下。谢谢。</p>
<p>重申一下,我无法开始工作的是 pauseSpeakingAtBoundary。根据 phonegaps 文档,语音合成由 javascript 执行程序运行。</p>
<pre><code>//
//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 = ;
AVSpeechSynthesizer *synthesizer = [ init];
synthesizer.delegate = self;
if (echo != nil && > 0 ) {
pluginResult = ;
if( !) {
AVSpeechUtterance *utterance = [ initWithString:echo];
utterance.rate = 0.20;
utterance.voice = ;
;
} else {
NSLog(@"Pausing");
;
}
} else {
pluginResult = ;
}
;
}
@end
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>我设法通过将 pauseSpeaking... 和 continueSpeaking 分离为不同的函数并从 javascript exec 执行它们来使其工作。这就是 Echo.m 的外观:</p>
<pre><code>//
//Echo.m
//Plugin
//
//
//
//
#import "Echo.h"
@implementation Echo
- (void)echo:(CDVInvokedUrlCommand*)command
{
self.synthesizer = [ init];
self.synthesizer.delegate = self;
CDVPluginResult* pluginResult = nil;
NSString* echo = ;
if (echo != nil && > 0 ) {
pluginResult = ;
AVSpeechUtterance *utterance = [ initWithString:echo];
utterance.rate = 0.20;
utterance.voice = ;
;
} else {
pluginResult = ;
}
;
}
-(void)speechSynthesizerPause:(AVSpeechSynthesizer *)synthesizer {
;
NSLog(@"Pausing");
}
-(void)speechSynthesizerContinue:(AVSpeechSynthesizer *)synthesizer {
;
NSLog(@"Continue");
}
-(void)speechSynthesizer:(AVSpeechSynthesizer *)synthesizer didFinishSpeechUtterance:(AVSpeechUtterance *)utterance {
NSLog(@"Playback finished");
}
@end
</code></pre></p>
<p style="font-size: 20px;">关于用于phonegap pauseSpeakingAtBoundary的ios AVSpeechSynthesizer插件不起作用,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/20192238/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/20192238/
</a>
</p>
页:
[1]