diff options
Diffstat (limited to 'src/espeak.c')
-rw-r--r-- | src/espeak.c | 40 |
1 files changed, 9 insertions, 31 deletions
diff --git a/src/espeak.c b/src/espeak.c index dc8880b..265a243 100644 --- a/src/espeak.c +++ b/src/espeak.c @@ -27,24 +27,19 @@ struct Espeak GOutputStream *buffer; }; -static unsigned char wave_hdr[44] = { - 'R','I','F','F',0x24,0xf0,0xff,0x7f,'W','A','V','E','f','m','t',' ', - 0x10,0,0,0,1,0,1,0, 9,0x3d,0,0,0x12,0x7a,0,0, - 2,0,0x10,0,'d','a','t','a', 0x00,0xf0,0xff,0x7f}; - pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; static GOutputStream *buffer = NULL; static gint sample_rate = 0; static const espeak_VOICE **voices = NULL; static gint -read_cb(short * wav, int numsamples, espeak_EVENT * events) +read_cb(short * data, int numsamples, espeak_EVENT * events) { - if (wav == NULL) + if (data == NULL) return 0; if (numsamples > 0) - g_output_stream_write(buffer, wav, numsamples*2, NULL, NULL); + g_output_stream_write(buffer, data, numsamples*2, NULL, NULL); return 0; } @@ -79,6 +74,12 @@ espeak_new() return es; } +gint +espeak_sample_rate() +{ + return sample_rate; +} + gchar** espeak_voices() { @@ -101,9 +102,6 @@ espeak_say(struct Espeak *es, const gchar *text, const gchar *voice, guint pitch, guint rate) { g_seekable_seek(G_SEEKABLE(es->buffer), 0, G_SEEK_SET, NULL, NULL); - g_output_stream_write(es->buffer, wave_hdr, 24, NULL, NULL); - g_seekable_seek(G_SEEKABLE(es->buffer), 8, G_SEEK_CUR, NULL, NULL); - g_output_stream_write(es->buffer, wave_hdr+32, 12, NULL, NULL); pthread_mutex_lock(&mutex); buffer = es->buffer; @@ -118,26 +116,6 @@ espeak_say(struct Espeak *es, const gchar *text, const gchar *voice, if (status != EE_OK) return FALSE; - void write4bytes(unsigned char *ptr, int value) - { - int ix; - - for(ix=0; ix<4; ix++) - { - *ptr++ = value & 0xff; - value = value >> 8; - } - } - - GMemoryOutputStream *mb = G_MEMORY_OUTPUT_STREAM(es->buffer); - unsigned char *ptr = g_memory_output_stream_get_data(mb); - guint size = g_memory_output_stream_get_data_size(mb); - - write4bytes(ptr+24, sample_rate); - write4bytes(ptr+28, sample_rate*2); - write4bytes(ptr+4, size-8); - write4bytes(ptr+40, size-44); - return TRUE; } |