示例#1
0
void QtSpeech_proc::say(QString text) {
    try {
        if (player)
        {
            player->stop();
            delete player;
        }
        player = new WavePlayer;

        if (!init) {
            int heap_size = FESTIVAL_HEAP_SIZE;
            festival_initialize(true,heap_size);
            init = true;
        }
        has_error = false;
        EST_String est_text(text.toUtf8());
        EST_Wave est_wave;
        SysCall(festival_text_to_wave(est_text, est_wave), QtSpeech::LogicError);
        EST_String est_file(player->filePath().toUtf8());
        est_wave.save(est_file);

        connect(player, SIGNAL(finished(int)), this, SIGNAL(finished()));
        connect(player, SIGNAL(finished(int)), player, SLOT(deleteLater()));
        player->play();
    }
    catch(QtSpeech::LogicError e) {
        has_error = true;
        err = e;
    }
}
示例#2
0
int main(void)
{
    EST_Wave wave;
    int heap_size = 210000;  // default scheme heap size
    int load_init_files = 1; // we want the festival init files loaded

    festival_initialize(load_init_files,heap_size);

    //festival_say_file("/etc/issue.text");

    //festival_eval_command("(voice_msu_ru_nsh_clunits)");
    //festival_say_text("а");
    
    festival_eval_command("(voice_ked_diphone)");
    festival_say_text("privet, suchka. blyahui");

    festival_text_to_wave("hello world",wave);
    wave.save("/tmp/wave.wav","riff");

    // festival_say_file puts the system in async mode so we better
    // wait for the spooler to reach the last waveform before exiting
    // This isn't necessary if only festival_say_text is being used (and
    // your own wave playing stuff)
    festival_wait_for_spooler();

    return 0;
}
示例#3
0
文件: tts.cpp 项目: sub77/hobbycode
int TTS::textToWave(const char *text, const char *path)
{
  EST_String str(text);
  EST_String dest(path);
  const int flag = festival_text_to_wave(str, wave);
  wave.save(dest, "riff");
  return flag;
}
void FestivalSynthesizer::synthSpeech ( std::string text )
{
    if ( pa_simple_ )
    {
        EST_Wave wave;
        festival_text_to_wave( text.c_str(), wave );
        int error;
        pa_simple_write( pa_simple_, &(wave.a(0)), wave.length()*2, &error );
    }
    else
    {
        ROS_ERROR( "Cannot snyth speec. Initilization failed." );
    }
}
void FestivalSynthesizer::initFestival()
{
    int heap_size = 210000;   // default scheme heap size
    int load_init_files = 1;  // we want the festival init files loaded

    festival_initialize(load_init_files, heap_size);

    try
    {
        const char* cfgFilename = "../config.cfg";

        Config cfg(cfgFilename);
        std::string voice = cfg.get("Voice");

        if ( voice == "female" )
        {
            festival_eval_command( "(voice_us1_mbrola)" );
            festival_eval_command( "(defvar Styles '((default 140 22 1.0)) \"Available voice styles\")" );
            festival_eval_command( "(defvar style_default 'default \"Default voice style\")" );
            festival_eval_command( "(defvar current_style 'none \"Current voice style\")" );
            festival_eval_command( "(define (Style selected_style) (let ((style (assoc selected_style Styles)))"
                                   "(if (not style) (set! style (assoc 'default Styles)))"
                                   "(let ((model_mean (cadr (assoc 'model_f0_mean  int_lr_params)))"
                                   "(model_std  (cadr (assoc 'model_f0_std   int_lr_params)))"
                                   "(new_mean (cadr style)) (new_std (cadr (cdr style)))"
                                   "(new_stretch (cadr (cdr (cdr style)))))"
                                   "(set! int_lr_params (list (list 'target_f0_mean new_mean)"
                                   "(list 'target_f0_std  new_std) (list 'model_f0_mean  model_mean)"
                                   "(list 'model_f0_std   model_std)))"
                                   "(Parameter.set 'Duration_Stretch new_stretch)"
                                   "(set! current_style (car style)) (list (car style) new_mean new_std new_stretch) ) ) )" );
            festival_eval_command( "(define (NewStyle style_name mean std stretch)"
                                   "(set! Styles (cons (list style_name mean std stretch) Styles)))" );
            festival_eval_command( "(NewStyle 'lisa 280 50 1.2)" );
            festival_eval_command( "(Style 'lisa)" );
        }
    }
    catch(const std::exception& e)
    {
        std::cerr << e.what() << std::endl;
    }

    // Check sampling rate
    EST_Wave wave;
    festival_text_to_wave( "init", wave );

    // Init pulse audio
    pa_sample_spec sample_spec;
    sample_spec.format = PA_SAMPLE_S16NE;
    sample_spec.channels = 1;
    sample_spec.rate = wave.sample_rate();

    pa_simple_ = pa_simple_new( NULL,                                   // Use the default server.
                                "FestivalSynthesizer",                  // Our application's name.
                                PA_STREAM_PLAYBACK,                     // Playback stream.
                                NULL,                                   // Use the default device.
                                "Festival Synthesizer (TalkingHead)",   // Description of our stream.
                                &sample_spec,                           // Our sample format.
                                NULL,                                   // Use default channel map
                                NULL,                                   // Use default buffering attributes.
                                NULL                                    // Ignore error code.
                                );

    if ( !pa_simple_ )
    {
        ROS_ERROR ( "Error initializing PulseAudio!" );
    }
}