iphone - iPhone 上的文字转语音

标签 iphone objective-c cocoa-touch text-to-speech

<分区>

实现类似于 AppleScript 的 say "words" 的东西有多难?
也就是说,它只是一个二进制链接和一个导入,还是像 libxml 实现一样困惑的东西?

编辑:我的回答解决了这个问题。


  • 阿卡佩拉
    • 严重盗版
    • SDK 250 欧元,不包括更新
  • 伊沃娜
    • 网站不提供与其他网站相同的 iOS 版本
    • 不感兴趣
  • 语音文本
    • 网站丑陋且难以导航
    • 不感兴趣
  • 打开耳朵
    • 开源,绝对加分
    • 迄今为止我听说过的最好的离线 TTS。
  • 飞来飞去
    • 质量极低,不值得使用
    • 照原样糟透了。 OE 对此进行了很大改进。
  • 谷歌语音合成
    • 很好,但需要网络连接
    • 不理想

最佳答案

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

与此相关,您可以通过以下方式使用 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];    
}

Apple 的画外音框架是私有(private)的,只能用于辅助功能。至少如果您希望您的申请获得批准。但是,如果您想在决定使用哪个系统时使用它,这里是:

// 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];
}

关于iphone - iPhone 上的文字转语音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6347072/

相关文章:

iphone - 并加载 NIB/XIB 文件?

iphone - 使用分组 TableView 时 IOS 键盘关闭

iphone - 删除其他框架后得到无法识别的选择器

objective-c - 在 iPhone 中带有购物车按钮的 Paypal

ios - 如何找到包含给定字符的字体?

html - 在 ios/safari/iPhone 上设置 HTML 选择标签的样式

iphone - 调用用户坐标、加载 PHP 文件并根据 UIApplicationDidBecomeActiveNotification 更新 UI

iphone - Objective-C : Accessing constants from other classes

ios - 点击并按住以在 UILabel 中显示完整文本

ios - 使用视觉格式语言使 UIButton 之间的间距相等