[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 8/9] moved module_main.c from ivona.c to Makefile.am
From: |
Andrei Kholodnyi |
Subject: |
[PATCH 8/9] moved module_main.c from ivona.c to Makefile.am |
Date: |
Mon, 6 Sep 2010 23:18:20 +0200 |
created ivona_client.h
moved functions with speechd specific declarations from ivona_client.c to
ivona.c
---
src/modules/Makefile.am | 2 +-
src/modules/ivona.c | 169 +++++++++++++++++++++++++++++++++++++++---
src/modules/ivona_client.c | 175 +++++--------------------------------------
src/modules/ivona_client.h | 36 +++++++++
4 files changed, 215 insertions(+), 167 deletions(-)
create mode 100644 src/modules/ivona_client.h
diff --git a/src/modules/Makefile.am b/src/modules/Makefile.am
index 0a53c91..72d5d36 100644
--- a/src/modules/Makefile.am
+++ b/src/modules/Makefile.am
@@ -50,7 +50,7 @@ sd_espeak_SOURCES = espeak.c module_main.c module_utils.c
module_utils.h
sd_espeak_LDFLAGS = @RPATH@ '$(spdlibdir)'
sd_espeak_LDADD = -lsdaudio -lespeak -ldotconf @glib_libs@ @SNDFILE_LIBS@
@gthread_libs@ @EXTRA_ESPEAK_LIBS@
-sd_ivona_SOURCES = ivona.c module_utils.c module_utils.h
+sd_ivona_SOURCES = ivona.c ivona_client.c module_main.c module_utils.c
module_utils.h
sd_ivona_LDFLAGS = @RPATH@ '$(spdlibdir)'
sd_ivona_LDADD = -lsdaudio -ldumbtts -lpthread -ldotconf @glib_libs@
@SNDFILE_LIBS@ @gthread_libs@
diff --git a/src/modules/ivona.c b/src/modules/ivona.c
index 68e10de..182fd5c 100644
--- a/src/modules/ivona.c
+++ b/src/modules/ivona.c
@@ -32,6 +32,7 @@
#include "fdset.h"
#include "module_utils.h"
+#include "ivona_client.h"
#if HAVE_SNDFILE
#include <sndfile.h>
@@ -58,6 +59,10 @@ signed int ivona_cap_mode=0;
int ivona_punct_mode=0;
/* Internal functions prototypes */
+static int ivona_get_msgpart(struct dumbtts_conf *conf, EMessageType type,
+ char **msg, char *icon, char **buf, int *len,
+ int cap_mode, char *delimeters, int punct_mode,
+ char *punct_some);
static void ivona_set_volume(signed int volume);
static void ivona_set_punctuation_mode(EPunctMode punct_mode);
static void ivona_set_cap_let_recogn(ECapLetRecogn cap_mode);
@@ -80,8 +85,6 @@ MOD_OPTION_1_STR(IvonaSpeakerName);
static struct dumbtts_conf *ivona_conf;
-#include "ivona_client.c"
-
/* Public functions */
int
@@ -126,7 +129,7 @@ module_init(char **status_info)
info = g_string_new("");
/* Init Ivona */
- if (ivona_init_sock()) {
+ if (ivona_init_sock(IvonaServerHost, IvonaServerPort)) {
DBG("Couldn't init socket parameters");
*status_info = strdup("Can't initialize socket. "
"Check server host/port.");
@@ -269,7 +272,148 @@ module_close(int status)
}
/* Internal functions */
+static int get_unichar(char **str)
+{
+ wchar_t wc;
+ int n;
+ wc=*(*str)++ & 255;
+ if ((wc & 0xe0)==0xc0) {
+ wc &=0x1f;
+ n=1;
+ }
+ else if ((wc & 0xf0)==0xe0) {
+ wc &=0x0f;
+ n=2;
+ }
+ else if ((wc & 0xf8)==0xf0) {
+ wc &=0x07;
+ n=3;
+ }
+ else if ((wc & 0xfc)==0xf8) {
+ wc &=0x03;
+ n=4;
+ }
+ else if ((wc & 0xfe)==0xfc) {
+ wc &=0x01;
+ n=5;
+ }
+ else return wc;
+ while (n--) {
+ if ((**str & 0xc0) != 0x80) {
+ wc='?';
+ break;
+ }
+ wc=(wc << 6) | ((*(*str)++) & 0x3f);
+ }
+ return wc;
+}
+
+static int ivona_get_msgpart(struct dumbtts_conf *conf, EMessageType type,
+ char **msg, char *icon, char **buf, int *len,
+ int cap_mode, char *delimeters, int punct_mode,
+ char *punct_some)
+{
+ int rc;
+ int isicon;
+ int n,pos,bytes;
+ wchar_t wc;
+ char xbuf[1024];
+
+ if (!*msg) return 1;
+ if (!**msg) return 1;
+ isicon=0;
+ icon[0]=0;
+ if (*buf) **buf=0;
+ DBG("Ivona message %s type %d\n",*msg,type);
+ switch(type) {
+ case MSGTYPE_SOUND_ICON:
+ if (strlen(*msg)<63) {
+ strcpy(icon,*msg);
+ rc=0;
+ }
+ else {
+ rc=1;
+ }
+ *msg=NULL;
+ return rc;
+
+ case MSGTYPE_SPELL:
+ wc=get_unichar(msg);
+ if (!wc) {
+ *msg=NULL;
+ return 1;
+ }
+ n=dumbtts_WCharString(conf,wc,*buf,*len,cap_mode,&isicon);
+ if (n>0) {
+ *len=n+128;
+ *buf=xrealloc(*buf,*len);
+
n=dumbtts_WCharString(conf,wc,*buf,*len,cap_mode,&isicon);
+ }
+ if (n) {
+ *msg=NULL;
+ return 1;
+ }
+ if (isicon) strcpy(icon,"capital");
+ return 0;
+
+ case MSGTYPE_KEY:
+ case MSGTYPE_CHAR:
+
+ if (type == MSGTYPE_KEY) {
+
n=dumbtts_KeyString(conf,*msg,*buf,*len,cap_mode,&isicon);
+ }
+ else {
+
n=dumbtts_CharString(conf,*msg,*buf,*len,cap_mode,&isicon);
+ }
+ DBG("Got n=%d",n);
+ if (n>0) {
+ *len=n+128;
+ *buf=xrealloc(*buf,*len);
+ if (type == MSGTYPE_KEY) {
+
n=dumbtts_KeyString(conf,*msg,*buf,*len,cap_mode,&isicon);
+ }
+ else {
+
n=dumbtts_CharString(conf,*msg,*buf,*len,cap_mode,&isicon);
+ }
+ }
+ *msg=NULL;
+
+ if (!n && isicon) strcpy(icon,"capital");
+ return n;
+
+ case MSGTYPE_TEXT:
+ pos=0;
+ bytes=module_get_message_part(*msg,xbuf,&pos, 1023,delimeters);
+ DBG("Got bytes %d, %s",bytes,xbuf);
+ if (bytes <= 0) {
+ *msg=NULL;
+ return 1;
+ }
+ *msg+=pos;
+ xbuf[bytes]=0;
+
+
+
n=dumbtts_GetString(conf,xbuf,*buf,*len,punct_mode,punct_some,",.;:!?");
+ if (n>0) {
+ *len=n+128;
+ *buf=xrealloc(*buf,*len);
+
n=dumbtts_GetString(conf,xbuf,*buf,*len,punct_mode,punct_some,",.;:!?");
+ }
+ if (n) {
+ *msg=NULL;
+ return 1;
+ }
+ DBG("Returning to Ivona |%s|",*buf);
+ return 0;
+
+ default:
+
+ *msg=NULL;
+ DBG("Unknown message type\n");
+ return 1;
+ }
+}
void*
_ivona_speak(void* nothing)
@@ -338,7 +482,11 @@ _ivona_speak(void* nothing)
DBG("Got icon");
}
if (!audio && !icon[0]) {
- if(!msg || !*msg || ivona_get_msgpart(&msg,&icon,&buf,&len)) {
+ if(!msg || !*msg
+ || ivona_get_msgpart(ivona_conf, ivona_message_type,
+ &msg,icon,&buf,&len,ivona_cap_mode,
+ IvonaDelimiters, ivona_punct_mode,
+ IvonaPunctuationSome)) {
ivona_speaking=0;
if (ivona_stop) module_report_event_stop();
else module_report_event_end();
@@ -361,7 +509,10 @@ _ivona_speak(void* nothing)
next_icon[0]=0;
if (msg && *msg) {
- if (!ivona_get_msgpart(&msg,&next_icon,&buf,&len)) {
+ if (!ivona_get_msgpart(ivona_conf, ivona_message_type, &msg,
+ next_icon, &buf, &len, ivona_cap_mode,
+ IvonaDelimiters, ivona_punct_mode,
+ IvonaPunctuationSome)) {
if (buf && *buf) {
next_offset=0;
next_audio=ivona_get_wave_from_cache(buf,&next_samples);
@@ -381,7 +532,7 @@ _ivona_speak(void* nothing)
break;
}
if (icon[0]) {
- play_icon(icon);
+ play_icon(IvonaSoundIconPath, icon);
if (ivona_stop) {
ivona_speaking=0;
module_report_event_stop();
@@ -466,9 +617,3 @@ ivona_set_punctuation_mode(EPunctMode punct_mode)
break;
}
}
-
-
-
-#include "module_main.c"
-
-
diff --git a/src/modules/ivona_client.c b/src/modules/ivona_client.c
index 7847c36..b234ce6 100644
--- a/src/modules/ivona_client.c
+++ b/src/modules/ivona_client.c
@@ -21,171 +21,40 @@
*
*/
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
#include <fcntl.h>
#include <netdb.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
+#include <unistd.h>
+
+#include <glib.h>
+#include <libdumbtts.h>
+
+#include "module_utils.h"
+#include "ivona_client.h"
static struct sockaddr_in sinadr;
-static char *ivona_get_wave_from_cache(char *to_say,int *nsamples);
-static void ivona_store_wave_in_cache(char *to_say,char *wave,int nsamples);
+char *ivona_get_wave_from_cache(char *to_say,int *nsamples);
+void ivona_store_wave_in_cache(char *to_say,char *wave,int nsamples);
-int ivona_init_sock(void)
+int ivona_init_sock(char *host, int port)
{
- if (!inet_aton(IvonaServerHost,&sinadr.sin_addr)) {
- struct hostent *h = gethostbyname(IvonaServerHost);
+ if (!inet_aton(host,&sinadr.sin_addr)) {
+ struct hostent *h = gethostbyname(host);
if (!h) return -1;
memcpy(&sinadr.sin_addr, h->h_addr, sizeof(struct in_addr));
endhostent();
}
sinadr.sin_family = AF_INET;
- sinadr.sin_port = htons(IvonaServerPort);
+ sinadr.sin_port = htons(port);
return 0;
}
-static int get_unichar(char **str)
-{
- wchar_t wc;
- int n;
- wc=*(*str)++ & 255;
- if ((wc & 0xe0)==0xc0) {
- wc &=0x1f;
- n=1;
- }
- else if ((wc & 0xf0)==0xe0) {
- wc &=0x0f;
- n=2;
- }
- else if ((wc & 0xf8)==0xf0) {
- wc &=0x07;
- n=3;
- }
- else if ((wc & 0xfc)==0xf8) {
- wc &=0x03;
- n=4;
- }
- else if ((wc & 0xfe)==0xfc) {
- wc &=0x01;
- n=5;
- }
- else return wc;
- while (n--) {
- if ((**str & 0xc0) != 0x80) {
- wc='?';
- break;
- }
- wc=(wc << 6) | ((*(*str)++) & 0x3f);
- }
- return wc;
-}
-
-int ivona_get_msgpart(char **msg,char *icon,char **buf,int *len)
-{
- int rc;
- int isicon;
- int n,pos,bytes;
- wchar_t wc;
- char xbuf[1024];
-
- if (!*msg) return 1;
- if (!**msg) return 1;
- isicon=0;
- icon[0]=0;
- if (*buf) **buf=0;
- DBG("Ivona message %s type %d\n",*msg,ivona_message_type);
- switch(ivona_message_type) {
- case MSGTYPE_SOUND_ICON:
- if (strlen(*msg)<63) {
- strcpy(icon,*msg);
- rc=0;
- }
- else {
- rc=1;
- }
- *msg=NULL;
- return rc;
-
- case MSGTYPE_SPELL:
- wc=get_unichar(msg);
- if (!wc) {
- *msg=NULL;
- return 1;
- }
-
n=dumbtts_WCharString(ivona_conf,wc,*buf,*len,ivona_cap_mode,&isicon);
- if (n>0) {
- *len=n+128;
- *buf=xrealloc(*buf,*len);
-
n=dumbtts_WCharString(ivona_conf,wc,*buf,*len,ivona_cap_mode,&isicon);
- }
- if (n) {
- *msg=NULL;
- return 1;
- }
- if (isicon) strcpy(icon,"capital");
- return 0;
-
- case MSGTYPE_KEY:
- case MSGTYPE_CHAR:
-
- if (ivona_message_type == MSGTYPE_KEY) {
-
n=dumbtts_KeyString(ivona_conf,*msg,*buf,*len,ivona_cap_mode,&isicon);
- }
- else {
-
n=dumbtts_CharString(ivona_conf,*msg,*buf,*len,ivona_cap_mode,&isicon);
- }
- DBG("Got n=%d",n);
- if (n>0) {
- *len=n+128;
- *buf=xrealloc(*buf,*len);
- if (ivona_message_type == MSGTYPE_KEY) {
-
n=dumbtts_KeyString(ivona_conf,*msg,*buf,*len,ivona_cap_mode,&isicon);
- }
- else {
-
n=dumbtts_CharString(ivona_conf,*msg,*buf,*len,ivona_cap_mode,&isicon);
- }
- }
- *msg=NULL;
-
- if (!n && isicon) strcpy(icon,"capital");
- return n;
-
- case MSGTYPE_TEXT:
- pos=0;
- bytes=module_get_message_part(*msg,xbuf,&pos,
1023,IvonaDelimiters);
- DBG("Got bytes %d, %s",bytes,xbuf);
- if (bytes <= 0) {
- *msg=NULL;
- return 1;
- }
- *msg+=pos;
- xbuf[bytes]=0;
-
-
-
n=dumbtts_GetString(ivona_conf,xbuf,*buf,*len,ivona_punct_mode,IvonaPunctuationSome,",.;:!?");
-
- if (n>0) {
- *len=n+128;
- *buf=xrealloc(*buf,*len);
-
n=dumbtts_GetString(ivona_conf,xbuf,*buf,*len,ivona_punct_mode,IvonaPunctuationSome,",.;:!?");
- }
- if (n) {
- *msg=NULL;
- return 1;
- }
- DBG("Returning to Ivona |%s|",*buf);
- return 0;
-
- default:
-
- *msg=NULL;
- DBG("Unknown message type\n");
- return 1;
- }
-}
-
-
#define BASE_WAVE_SIZE 65536
#define STEP_WAVE_SIZE 32768
@@ -336,19 +205,17 @@ ivona_play_file(char *filename)
return result;
}
-
-void play_icon(char *name)
+void play_icon(char* path, char *name)
{
- int len = strlen(IvonaSoundIconPath) + strlen(name) + 2;
+ int len = strlen(path) + strlen(name) + 2;
char *buf = g_malloc(len);
- sprintf(buf, "%s/%s", IvonaSoundIconPath, name);
+ sprintf(buf, "%s/%s", path, name);
ivona_play_file(buf);
g_free(buf);
}
#define IVONA_CACHE_SIZE 256
#define IVONA_CACHE_MAX_SAMPLES 65536
-#define IVONA_CACHE_MAX_STRLEN 11
static int ivona_cache_count;
@@ -360,7 +227,7 @@ static struct ivona_cache {
char *wave;
} ica_head,ica_tail,icas[IVONA_CACHE_SIZE];
-static void ivona_init_cache(void)
+void ivona_init_cache(void)
{
ica_head.pred=&ica_tail;
ica_tail.succ=&ica_head;
@@ -418,7 +285,7 @@ void ivona_store_wave_in_cache(char *str,char *wave,int
samples)
DBG("Stored cache %s",str);
}
-static char *ivona_get_wave_from_cache(char *to_say,int *samples)
+char *ivona_get_wave_from_cache(char *to_say,int *samples)
{
struct ivona_cache *ica;
if (strlen(to_say)>IVONA_CACHE_MAX_STRLEN) return NULL;
diff --git a/src/modules/ivona_client.h b/src/modules/ivona_client.h
new file mode 100644
index 0000000..4370ef1
--- /dev/null
+++ b/src/modules/ivona_client.h
@@ -0,0 +1,36 @@
+/*
+ * ivona_client.h - Declarations from ivona_client.c
+ *
+ * Copyright (C) Bohdan R. Rau 2008 <ethanak at polip.com>
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this package; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ */
+#ifndef IVONA_CLIENT_H
+#define IVONA_CLIENT_H
+
+/* A constant, used in both ivona.c and ivona_client.c */
+#define IVONA_CACHE_MAX_STRLEN 11
+
+int ivona_init_sock(char *host, int port);
+int ivona_send_string(char *to_say);
+char *ivona_get_wave_fd(int fd, int *nsamples, int *offset);
+char *ivona_get_wave(char *to_say, int *nsamples, int *offset);
+void play_icon(char *path, char *name);
+void ivona_init_cache(void);
+void ivona_store_wave_in_cache(char *to_say, char *wave, int nsamples);
+char *ivona_get_wave_from_cache(char *to_say, int *nsamples);
+#endif
--
1.6.0.4
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [PATCH 8/9] moved module_main.c from ivona.c to Makefile.am,
Andrei Kholodnyi <=