Текст в речь с помощью iPhone SDK - PullRequest
2 голосов
/ 22 апреля 2011

Я очень новичок в создании речи с использованием некоторого входного текста.Я попробовал это на следующем примере, и мне это удалось.Речь - это мужской голос. Но мне нужно сделать это как женский.Возможно ли справиться с этим?И, ребята, не могли бы вы предложить мне, какие настройки мы можем изменить в этом.

#import <Foundation/Foundation.h>
#import <AVFoundation/AVFoundation.h>


@interface FliteTTS : NSObject <AVAudioPlayerDelegate> 
{
    //NSData *soundObj;     // doesn't work yet - see note in FliteTTS.m
    AVAudioPlayer* audioPlayer;
}

// Use these:
-(void)speakText:(NSString *)text;
-(void)stopTalking;
-(void)setPitch:(float)pitch variance:(float)variance speed:(float)speed;
-(void)setVoice:(NSString *)voicename;
@end


#import "FliteTTS.h"
#import "flite.h"

cst_voice *register_cmu_us_kal();
cst_voice *register_cmu_us_kal16();
cst_voice *register_cmu_us_rms();
cst_voice *register_cmu_us_awb();
cst_voice *register_cmu_us_slt();
cst_voice *register_usenglish();
cst_wave *sound;
cst_voice *voice;

@implementation FliteTTS

-(id)init
{
    self = [super init];
    flite_init();
    // Set a default voice
    //voice = register_cmu_us_kal();
    //voice = register_cmu_us_kal16();
    //voice = register_cmu_us_rms();
    //voice = register_cmu_us_awb();
    //voice = register_cmu_us_slt();
    [self setVoice:@"cmu_us_kal"];
    return self;
}

-(void)speakText:(NSString *)text
{
    NSMutableString *cleanString;
    cleanString = [NSMutableString stringWithString:@""];
    if([text length] > 1)
    {
        int x = 0;
        while (x < [text length])
        {
            unichar ch = [text characterAtIndex:x];
            [cleanString appendFormat:@"%c", ch];
            x++;
        }
    }
    if(cleanString == nil)
    {       // string is empty
        cleanString = [NSMutableString stringWithString:@""];
    }
    sound = flite_text_to_wave([cleanString UTF8String], voice);




    NSArray *filePaths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory,   NSUserDomainMask, YES);
    NSString *recordingDirectory = [filePaths objectAtIndex: 0];
    // Pick a file name
    NSString *tempFilePath = [NSString stringWithFormat: @"%@/%s", recordingDirectory, "temp.wav"];
    printf("\n TempFilePath:%s",[tempFilePath UTF8String]);

    // save wave to disk
    char *path; 
    path = (char*)[tempFilePath UTF8String];
    cst_wave_save_riff(sound, path);


    // Play the sound back.
    NSError *err;
    [audioPlayer stop];
    audioPlayer =  [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL  fileURLWithPath:tempFilePath] error:&err];
    [audioPlayer setDelegate:self];
    [audioPlayer prepareToPlay];
    [audioPlayer play];
    // Remove file
    [[NSFileManager defaultManager] removeItemAtPath:tempFilePath error:nil];

}

-(void)setPitch:(float)pitch variance:(float)variance speed:(float)speed
{
    feat_set_float(voice->features,"int_f0_target_mean", pitch);
    feat_set_float(voice->features,"int_f0_target_stddev",variance);
    feat_set_float(voice->features,"duration_stretch",speed); 
}

-(void)setVoice:(NSString *)voicename
{
    if([voicename isEqualToString:@"cmu_us_kal"]) {
        voice = register_cmu_us_kal();
    }
    else if([voicename isEqualToString:@"cmu_us_kal16"]) {
        voice = register_cmu_us_kal16();
    }
    else if([voicename isEqualToString:@"cmu_us_rms"]) {
        voice = register_cmu_us_rms();
    }
    else if([voicename isEqualToString:@"cmu_us_awb"]) {
        voice = register_cmu_us_awb();
    }
    else if([voicename isEqualToString:@"cmu_us_slt"]) {
        voice = register_cmu_us_slt();
    }

}

-(void)stopTalking
{
    [audioPlayer stop];
}

@end

Заранее спасибо, Sekhar

Ответы [ 2 ]

1 голос
/ 29 марта 2014

Если вы нашли хорошую статью для AVSpeechSynthesizer (iOS 7) из здесь Это имеет хорошее объяснение.

Arabic (Saudi Arabia) - ar-SA
Chinese (China) - zh-CN
Chinese (Hong Kong SAR China) - zh-HK
Chinese (Taiwan) - zh-TW
Czech (Czech Republic) - cs-CZ
Danish (Denmark) - da-DK
Dutch (Belgium) - nl-BE
Dutch (Netherlands) - nl-NL
English (Australia) - en-AU
English (Ireland) - en-IE
English (South Africa) - en-ZA
English (United Kingdom) - en-GB
English (United States) - en-US
Finnish (Finland) - fi-FI
French (Canada) - fr-CA
French (France) - fr-FR
German (Germany) - de-DE
Greek (Greece) - el-GR
Hindi (India) - hi-IN
Hungarian (Hungary) - hu-HU
Indonesian (Indonesia) - id-ID
Italian (Italy) - it-IT
Japanese (Japan) - ja-JP
Korean (South Korea) - ko-KR
Norwegian (Norway) - no-NO
Polish (Poland) - pl-PL
Portuguese (Brazil) - pt-BR
Portuguese (Portugal) - pt-PT
Romanian (Romania) - ro-RO
Russian (Russia) - ru-RU
Slovak (Slovakia) - sk-SK
Spanish (Mexico) - es-MX
Spanish (Spain) - es-ES
Swedish (Sweden) - sv-SE
Thai (Thailand) - th-TH
Turkish (Turkey) - tr-TR

надеюсь, это поможет вам

1 голос
/ 23 апреля 2011

Позвоните setVoice:@"cmu_us_slt", чтобы установить женский голос. Для мужского голоса с американским акцентом, звоните setVoice:@"cmu_us_rms".

...