iPhone上的文本转语音

5
有多难实现类似于AppleScript的say "words"呢?也就是说,这只是一个二进制链接和导入,还是一个像libxml实现一样混乱的东西?
编辑:我的答案解决了这个问题。
  • Acapela
    • 严重的敲诈
    • 250欧元的SDK,不包括更新
  • Ivona
    • 网站没有iOS版本与其他版本一起呈现
    • 不感兴趣
  • VoiceText
    • 网站丑陋且难以导航
    • 不感兴趣
  • OpenEars
    • 开源,绝对优势
    • 到目前为止我听到的最好的离线TTS。
  • Flite
    • 超低质量,不值得使用
    • 原样很差。 OE大大改进了它。
  • Google TTS
    • 不错,但需要网络连接
    • 不理想

请查看以下内容: https://bitbucket.org/sfoster/iphone-tts/ - Satish
请检查我的答案:https://dev59.com/A2nWa4cB1Zd3GeqP03m2#12839821 - Shamsudheen TK
2个回答

7
我已经调查了这个问题,不幸的是,选项要么非常昂贵,要么质量很差:

与此相关的是,以下是如何使用 Google 的在线 TTS(代码取自 iPhone SDK - Google TTS and encoding):

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"file.mp3"];

NSString *text = @"You are one chromosome away from being a potato.";
NSString *urlString = [NSString stringWithFormat:@"http://www.translate.google.com/translate_tts?tl=en&q=%@",text];
NSURL *url = [NSURL URLWithString:[urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSMutableURLRequest* request = [[[NSMutableURLRequest alloc] initWithURL:url] autorelease];
[request setValue:@"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:2.0.1) Gecko/20100101 Firefox/4.0.1" forHTTPHeaderField:@"User-Agent"];
NSURLResponse* response = nil;
NSError* error = nil;
NSData* data = [NSURLConnection sendSynchronousRequest:request
                                     returningResponse:&response
                                                 error:&error];
[data writeToFile:path atomically:YES];

AVAudioPlayer  *player;
NSError        *err;
if ([[NSFileManager defaultManager] fileExistsAtPath:path]) 
{    
    player = [[AVAudioPlayer alloc] initWithContentsOfURL:
              [NSURL fileURLWithPath:path] error:&err];
    player.volume = 0.4f;
    [player prepareToPlay];
    [player setNumberOfLoops:0];
    [player play];    
}

苹果的语音转换框架是私有的,只能用于辅助功能。如果您希望应用程序得到批准,那么至少要遵守这个规定。但是,如果您想在决定使用哪个系统时使用它,这里是:

// Not App Store safe. Only available in real devices.
// See http://arstechnica.com/apple/2010/02/iphone-voiceservices-looking-under-the-hood/

#define RTLD_LAZY 0x1
#define RTLD_NOW 0x2
#define RTLD_LOCAL 0x4
#define RTLD_GLOBAL 0x8

NSObject *voiceSynthesizer;
void *voiceServices;

-(void) say:(NSString*)text {
    if (!voiceSynthesizer)
    {
        NSString *vsLocation = @"/System/Library/PrivateFrameworks/VoiceServices.framework/VoiceServices";
        voiceServices = dlopen(vsLocation.UTF8String, RTLD_LAZY);
        voiceSynthesizer = [NSClassFromString(@"VSSpeechSynthesizer") new];
    }
    [voiceSynthesizer performSelector:@selector(startSpeakingString:) withObject:text];
}

看起来不错。我会尽力而为。(无论是使用Google选项还是其他方式。) - Thromordyn
我似乎无法让在线TTS工作... - Thromordyn
谎言!我已经添加了MP3播放器代码,它应该可以工作。 - Jano
我敢肯定我搞砸了什么。那段代码看起来比我尝试的好看一些。// 高质量TTS选项有多大?价格不考虑,它们与Flite相比如何?我的电脑无法在不完全锁定的情况下构建超过200个文件。(最终我等了两分钟才打开强制退出应用程序窗口,以便使用Firefox。)要在Xcode 4中使用Flite需要像Mac Pro这样的东西。这个版本效率极低,并且太愿意从其他所有资源中窃取资源。 - Thromordyn
方法“-applicationDocumentsDirectory”未找到 // 可以假设我不能使用离线TTS而不会在构建时锁定计算机的UI吗? - Thromordyn
显示剩余3条评论

1

从SO上的一些问题(忘记是哪一个了,找不到了),我得到了一个指向OpenEars的链接。
对于这么轻量级的东西,我真的不能抱怨。

它有点令人困惑,但文档都是针对Xcode 4的。除非用户出错,否则它不会炸掉一个项目。有一些警告(其中一些看起来应该会在运行时导致崩溃),但目前看起来还不错。

编辑:最新的OE版本安装要容易得多。绝对推荐。


2
OpenEars的质量实际上与flite相同。这意味着它的质量很差。 - vodkhang
OpenEars的质量明显比仅有的Flite要好得多,而且它更加强大。 - Thromordyn

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接