• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

用于phonegap pauseSpeakingAtBoundary的ios AVSpeechSynthesizer插件不起作用

[复制链接]
菜鸟教程小白 发表于 2022-12-12 16:40:23 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

我为 phonegap 制作了一个插件,允许用户使用 AVSpeechSynthesizer 听到一段文本,但我似乎无法让 pauseSpeakingAtBoundary 工作。 p>

出于测试目的,它当前接收要合成的文本字符串或显示“PAUSE”的字符串,并仅检查 if (![echo isEqual'PAUSE']) 以确定它是否应该尝试暂停话语。讲话开始并在收到“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) echoNSMutableArray*)arguments;



@end


//
//  Echo.m
//  Plugin
//
//
//
//

#import "Echo.h"

@implementation Echo



- (void)echoCDVInvokedUrlCommand*)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"AUSE"]) {

        AVSpeechUtterance *utterance = [[AVSpeechUtterance alloc] initWithString:echo];
        utterance.rate = 0.20;
        utterance.voice = [AVSpeechSynthesisVoice voiceWithLanguage"en-gb"];
        [synthesizer speakUtterance:utterance];

    } else {


        NSLog(@"ausing");

        [synthesizer pauseSpeakingAtBoundary:AVSpeechBoundaryImmediate];


    }





} else {
    pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
}

[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}


@end



Best Answer-推荐答案


我设法通过将 pauseSpeaking... 和 continueSpeaking 分离为不同的函数并从 javascript exec 执行它们来使其工作。这就是 Echo.m 的外观:

//
//  Echo.m
//  Plugin
//
//
//
//

#import "Echo.h"

@implementation Echo





- (void)echoCDVInvokedUrlCommand*)command
{

self.synthesizer = [[AVSpeechSynthesizer alloc] init];
self.synthesizer.delegate = self;

CDVPluginResult* pluginResult = nil;
NSString* echo = [command.arguments objectAtIndex:0];


if (echo != nil && [echo length] > 0 ) {

    pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:echo];


        AVSpeechUtterance *utterance = [[AVSpeechUtterance alloc] initWithString:echo];
        utterance.rate = 0.20;
        utterance.voice = [AVSpeechSynthesisVoice voiceWithLanguage"en-gb"];
        [self.synthesizer speakUtterance:utterance];     


} else {
    pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
}

[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}

-(void)speechSynthesizerPauseAVSpeechSynthesizer *)synthesizer {

[self.synthesizer pauseSpeakingAtBoundary:AVSpeechBoundaryImmediate];
NSLog(@"ausing");

}

-(void)speechSynthesizerContinueAVSpeechSynthesizer *)synthesizer {

   [self.synthesizer continueSpeaking];
    NSLog(@"Continue");

}


-(void)speechSynthesizerAVSpeechSynthesizer *)synthesizer didFinishSpeechUtteranceAVSpeechUtterance *)utterance {
NSLog(@"layback finished");
}


@end

关于用于phonegap pauseSpeakingAtBoundary的ios AVSpeechSynthesizer插件不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20192238/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap