无法听到 Text to Speech 的任何输出

Unable to hear any output from Text to Speech

我正在创建自己的 Codenameone 应用程序,该应用程序使用 IOS 8 中的文本转语音功能。我的应用程序使用与 DrSbaitso 演示中相同的本机 IOS 代码。我可以构建我的应用程序并将其成功部署到我的 IPhone,但是我永远无法听到 Text to Speech 的任何输出。我已验证正在调用本机接口,但我听不到任何声音。除了调用 IOS 文本转语音功能的本机接口之外,是否还有其他需要实现的东西?也许我需要在 IPhone 上启用某些功能才能使用 Text to Speech API?我列出了我正在使用的本机实现代码。

Header:

#import <Foundation/Foundation.h>

@interface com_testapp_demos_TTSImpl: NSObject {
}

-(void)say:(NSString*)param;
-(BOOL)isSupported;
@end

来源:

#import "com_testapp_demos_TTSImpl.h"
#import <AVFoundation/AVFoundation.h>

@implementation com_testapp_demos_TTSImpl

-(void)say:(NSString*)param{
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    AVSpeechSynthesisVoice *voice = [AVSpeechSynthesisVoice voiceWithLanguage:@"en-GB"];
    AVSpeechUtterance *utterance = [AVSpeechUtterance speechUtteranceWithString:param];
    AVSpeechSynthesizer *syn = [[[AVSpeechSynthesizer alloc] init]autorelease];
    utterance.rate = 0;
    utterance.voice = voice;
    [syn speakUtterance:utterance];
    [pool release];
}

-(BOOL)isSupported{
    return YES;
}

@end

确认音量已调高并且设备未处于静音模式。

请注意,在 iOS 中,设备可能处于静音模式并且仍在播放声音,因此这是一个常见错误!

AVSpeechSynthesizer works on simulator but not on device