예제 #1
0
static int save_dataset_comments (const dataset *dset)
{
    int i, j;
    cst_voice *v;
    cst_wave *w, *fullw = NULL;

    flite_init();
    v = register_cmu_us_kal();

    j = 0;
    for (i=0; i<N_COMMENTS; i++) {
	if (dset->comments[i] != NULL) {
	    if (j == 0) {
		fullw = flite_text_to_wave(dset->comments[i], v);
	    } else {
		w = flite_text_to_wave(dset->comments[i], v);
		concat_wave(fullw, w);
		delete_wave(w);
	    }
	    j++;
	}
    }

    cst_wave_save_riff(fullw, "gretl_flite.wav");
    delete_wave(fullw);

    return 0;
}
예제 #2
0
int flowm_say_text(TCHAR *text)
{
    char *s;
    int ns;
    cst_voice *v;

    if (previous_wave)
    {
        delete_wave(previous_wave);
        previous_wave = NULL;
    }

    s = cst_wstr2cstr(text);               /* text to synthesize */
    v = VoxDefs[flowm_selected_voice].v;   /* voice to synthesize with */

    feat_remove(v->features,"print_info_relation");
    if (flowm_selected_relation == 1)
        feat_set_string(v->features, "print_info_relation", "Word");
    if (flowm_selected_relation == 2)
        feat_set_string(v->features, "print_info_relation", "Segment");

    /* Do the synthesis */
    previous_wave = flite_text_to_wave(s,v);

    ns = cst_wave_num_samples(previous_wave);

    cst_free(s);
    audio_flush(fl_ad);
    audio_close(fl_ad); 
    fl_ad = NULL;

    return ns;
}
예제 #3
0
static switch_status_t flite_speech_feed_tts(switch_speech_handle_t *sh, char *text, switch_speech_flag_t *flags)
{
	flite_t *flite = (flite_t *) sh->private_info;

	flite->w = flite_text_to_wave(text, flite->v);

	return SWITCH_STATUS_SUCCESS;
}
예제 #4
0
static GstFlowReturn
gst_flite_test_src_create (GstBaseSrc * basesrc, guint64 offset,
    guint length, GstBuffer ** buffer)
{
  GstFliteTestSrc *src;
  int n_bytes;

  src = GST_FLITE_TEST_SRC (basesrc);

  n_bytes = src->info.channels * sizeof (gint16) * src->samples_per_buffer;

  while (gst_adapter_available (src->adapter) < n_bytes) {
    GstBuffer *buf;
    char *text;
    int i;
    GstMapInfo map;
    gint16 *data;
    cst_wave *wave;
    gsize size;

    text = get_channel_name (src, src->channel);

    wave = flite_text_to_wave (text, src->voice);
    g_free (text);
    cst_wave_resample (wave, src->info.rate);

    GST_DEBUG ("type %s, sample_rate %d, num_samples %d, num_channels %d",
        wave->type, wave->sample_rate, wave->num_samples, wave->num_channels);

    size = src->info.channels * sizeof (gint16) * wave->num_samples;
    buf = gst_buffer_new_and_alloc (size);

    gst_buffer_map (buf, &map, GST_MAP_WRITE);
    data = (gint16 *) map.data;
    memset (data, 0, size);
    for (i = 0; i < wave->num_samples; i++) {
      data[i * src->info.channels + src->channel] = wave->samples[i];
    }
    gst_buffer_unmap (buf, &map);

    src->channel++;
    if (src->channel == src->info.channels) {
      src->channel = 0;
    }

    gst_adapter_push (src->adapter, buf);
  }

  *buffer = gst_adapter_take_buffer (src->adapter, n_bytes);

  return GST_FLOW_OK;
}
예제 #5
0
파일: twatc.c 프로젝트: vrld/twat
void next_tweet(struct sockaddr_in* server, int chan)
{
    char buffer[BUFSIZE+1];
    memset(buffer, BUFSIZE, 0);
    receive_tweet(buffer, server);
    printf("%s\n", buffer);

    if (si.w[chan])
        delete_wave(si.w[chan]);

    si.w[chan]          = flite_text_to_wave(buffer, voice);
    si.done[chan]       = 0;
    si.pos[chan]        = 0;
    si.cur_delay[chan]  = 0.;
    si.rate_delay[chan] = 44100. / (double)si.w[chan]->sample_rate;
    /* play some tweets faster, some slower */
    si.rate_delay[chan] *= (.75 + .5 * (double)(rand() % 256) / 255.);
}
예제 #6
0
파일: flite.c 프로젝트: Angeldude/pd
/*--------------------------------------------------------------------
 * flite_synth : synthesize current text-buffer
 *--------------------------------------------------------------------*/
void flite_synth(t_flite *x) {
  cst_wave *wave;
  int i,vecsize;
  t_garray *a;
  t_float *vec;

# ifdef FLITE_DEBUG
  post("flite: got message 'synth'");
# endif

  // -- sanity checks
  if (!(a = (t_garray *)pd_findbyclass(x->x_arrayname, garray_class))) {
    pd_error(x,"flite: no such array '%s'", x->x_arrayname->s_name);
    return;
  }
  if (!x->textbuf) {
    pd_error(x,"flite: attempt to synthesize empty text-buffer!");
    return;
  }

# ifdef FLITE_DEBUG
  post("flite: flite_text_to_wave()");
# endif
  wave = flite_text_to_wave(x->textbuf,voice);

  if (!wave) {
    pd_error(x,"flite: synthesis failed for text '%s'", x->textbuf);
    return;
  }

  // -- resample
# ifdef FLITE_DEBUG
  post("flite: cst_wave_resample()");
# endif
  cst_wave_resample(wave,sys_getsr());

  // -- resize & write to our array
# ifdef FLITE_DEBUG
  post("flite: garray_resize(%d)", wave->num_samples);
# endif

  garray_resize(a, wave->num_samples);
  if (!garray_getfloatarray(a, &vecsize, &vec))
    pd_error(x,"flite: bad template for write to array '%s'", x->x_arrayname->s_name);

# ifdef FLITE_DEBUG
  post("flite: ->write to garray loop<-");
# endif
  for (i = 0; i < wave->num_samples; i++) {
    *vec++ = wave->samples[i]/32767.0;
  }

  // -- outlet synth-done-bang
  outlet_bang(x->x_obj.ob_outlet);

  // -- cleanup
  delete_wave(wave);

  // -- redraw
  garray_redraw(a);
}
예제 #7
0
파일: flite.c 프로젝트: razr/opentts
void *_flite_speak(void *nothing)
{
	AudioTrack track;
	cst_wave *wav;
	unsigned int pos;
	char *buf;
	int bytes;
	int ret;

	log_msg(OTTS_LOG_DEBUG, "flite: speaking thread starting.......\n");

	set_speaking_thread_parameters();

	while (1) {
		sem_wait(flite_semaphore);
		log_msg(OTTS_LOG_INFO, "Semaphore on\n");

		flite_stopped = 0;
		flite_speaking = 1;

		if (opentts_audio_set_volume(module_audio_id, flite_volume) < 0) {
			log_msg(OTTS_LOG_ERR,
			        "Can't set volume. audio not initialized?\n");
			continue;
		}

		/* TODO: free(buf) */
		buf =
		    (char *)g_malloc((FliteMaxChunkLength + 1) * sizeof(char));
		pos = 0;
		module_report_event_begin();
		while (1) {
			if (flite_stopped) {
				log_msg(OTTS_LOG_INFO,
					"Stop in child, terminating");
				flite_speaking = 0;
				module_report_event_stop();
				break;
			}
			bytes =
			    module_get_message_part(*flite_message, buf, &pos,
						    FliteMaxChunkLength,
						    FliteDelimiters);

			if (bytes < 0) {
				log_msg(OTTS_LOG_DEBUG, "End of message");
				flite_speaking = 0;
				module_report_event_end();
				break;
			}

			buf[bytes] = 0;
			log_msg(OTTS_LOG_DEBUG,
				"Returned %d bytes from get_part\n", bytes);
			log_msg(OTTS_LOG_NOTICE, "Text to synthesize is '%s'\n",
				buf);

			if (flite_pause_requested && (current_index_mark != -1)) {
				log_msg(OTTS_LOG_INFO,
					"Pause requested in parent, position %d\n",
					current_index_mark);
				flite_pause_requested = 0;
				flite_position = current_index_mark;
				break;
			}

			if (bytes > 0) {
				log_msg(OTTS_LOG_DEBUG, "Speaking in child...");

				log_msg(OTTS_LOG_NOTICE,
					"Trying to synthesize text");
				wav = flite_text_to_wave(buf, flite_voice);

				if (wav == NULL) {
					log_msg(OTTS_LOG_NOTICE,
						"Stop in child, terminating");
					flite_speaking = 0;
					module_report_event_stop();
					break;
				}

				track.num_samples = wav->num_samples;
				track.num_channels = wav->num_channels;
				track.sample_rate = wav->sample_rate;
				track.bits = 16;
				track.samples = wav->samples;
				flite_strip_silence(&track);

				log_msg(OTTS_LOG_INFO, "Got %d samples",
					track.num_samples);
				if (track.samples != NULL) {
					if (flite_stopped) {
						log_msg(OTTS_LOG_NOTICE,
							"Stop in child, terminating");
						flite_speaking = 0;
						module_report_event_stop();
						delete_wave(wav);
						break;
					}
					log_msg(OTTS_LOG_INFO,
						"Playing part of the message");
					switch (module_audio_id->format) {
					case SPD_AUDIO_LE:
						ret =
						    opentts_audio_play
						    (module_audio_id, track,
						     SPD_AUDIO_LE);
						break;
					case SPD_AUDIO_BE:
						ret =
						    opentts_audio_play
						    (module_audio_id, track,
						     SPD_AUDIO_BE);
						break;
					}
					if (ret < 0)
						log_msg(OTTS_LOG_WARN,
							"ERROR: spd_audio failed to play the track");
					if (flite_stopped) {
						log_msg(OTTS_LOG_NOTICE,
							"Stop in child, terminating (s)");
						flite_speaking = 0;
						module_report_event_stop();
						delete_wave(wav);
						break;
					}
				}
				delete_wave(wav);
			} else if (bytes == -1) {
				log_msg(OTTS_LOG_INFO,
					"End of data in speaking thread");
				flite_speaking = 0;
				module_report_event_end();
				break;
			} else {
				flite_speaking = 0;
				module_report_event_end();
				break;
			}

			if (flite_stopped) {
				log_msg(OTTS_LOG_NOTICE,
					"Stop in child, terminating");
				flite_speaking = 0;
				module_report_event_stop();
				break;
			}
		}
		flite_stopped = 0;
		g_free(buf);
	}

	flite_speaking = 0;

	log_msg(OTTS_LOG_NOTICE, "flite: speaking thread ended.......\n");

	pthread_exit(NULL);
}