38 #include <sys/socket.h>
40 #include <netinet/in.h>
41 #include <arpa/inet.h>
58 #define FESTIVAL_CONFIG "festival.conf"
60 #define MAXFESTLEN 2048
79 static char *
app =
"Festival";
88 static char *file_stuff_key =
"ft_StUfF_key";
99 for (k = 0; file_stuff_key[k] !=
'\0';) {
103 if ((*size) + k + 1 >= bufflen) {
105 bufflen += bufflen / 4;
112 if (file_stuff_key[k] == c)
114 else if ((c ==
'X') && (file_stuff_key[k+1] ==
'\0')) {
116 for (i = 0; i < k; i++, (*size)++)
117 buff[*size] = file_stuff_key[i];
121 for (i = 0; i < k; i++, (*size)++)
122 buff[*size] = file_stuff_key[i];
135 #if __BYTE_ORDER == __BIG_ENDIAN
150 #if __BYTE_ORDER == __BIG_ENDIAN
151 for (x = 0; x < length; x += 2) {
152 c = *(waveform + x + 1);
153 *(waveform + x + 1) = *(waveform + x);
158 if (write(0, waveform, length) < 0) {
226 if (needed >
sizeof(myf.frdata)) {
228 (
int)
sizeof(myf.frdata) / 2, needed/2);
229 needed =
sizeof(myf.frdata);
231 res = read(fds[0], myf.frdata, needed);
236 myf.f.samples = res / 2;
238 myf.f.src = __PRETTY_FUNCTION__;
239 myf.f.data.ptr = myf.frdata;
262 if (!res && owriteformat)
271 struct sockaddr_in serv_addr;
272 struct hostent *serverhost;
277 const char *cachedir;
279 const char *festivalcommand;
288 unsigned char MD5Res[16];
289 char MD5Hex[33] =
"";
300 char *newfestivalcommand;
342 const char *startcmd =
"(tts_textasterisk \"";
343 const char *endcmd =
"\" 'file)(quit)\n";
345 strln = strlen(startcmd) + strlen(
args.text) + strlen(endcmd) + 1;
347 snprintf(newfestivalcommand, strln,
"%s%s%s", startcmd,
args.text, endcmd);
348 festivalcommand = newfestivalcommand;
351 newfestivalcommand =
ast_alloca(strlen(festivalcommand) + strlen(
args.text) + 1);
353 for (x = 0, j = 0; x < strlen(festivalcommand); x++) {
354 if (festivalcommand[x] ==
'\\' && festivalcommand[x + 1] ==
'n') {
355 newfestivalcommand[j++] =
'\n';
357 }
else if (festivalcommand[x] ==
'\\') {
358 newfestivalcommand[j++] = festivalcommand[x + 1];
360 }
else if (festivalcommand[x] ==
'%' && festivalcommand[x + 1] ==
's') {
361 sprintf(&newfestivalcommand[j],
"%s",
args.text);
362 j += strlen(
args.text);
365 newfestivalcommand[j++] = festivalcommand[x];
367 newfestivalcommand[j] =
'\0';
368 festivalcommand = newfestivalcommand;
371 if (
args.interrupt && !strcasecmp(
args.interrupt,
"any"))
374 ast_debug(1,
"Text passed to festival server : %s\n",
args.text);
377 fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
385 memset(&serv_addr, 0,
sizeof(serv_addr));
387 if ((serv_addr.sin_addr.s_addr = inet_addr(host)) == -1) {
391 if (serverhost == NULL) {
396 memmove(&serv_addr.sin_addr, serverhost->h_addr, serverhost->h_length);
399 serv_addr.sin_family = AF_INET;
400 serv_addr.sin_port = htons(port);
402 if (connect(fd, (
struct sockaddr *)&serv_addr,
sizeof(serv_addr)) != 0) {
416 for (i = 0; i < 16; i++) {
417 snprintf(koko,
sizeof(koko),
"%X", (
unsigned)MD5Res[i]);
418 strncat(MD5Hex, koko,
sizeof(MD5Hex) - strlen(MD5Hex) - 1);
422 if (strlen(cachedir) + strlen(MD5Hex) + 1 <=
MAXFESTLEN && (usecache == -1)) {
423 snprintf(cachefile,
sizeof(cachefile),
"%s/%s", cachedir, MD5Hex);
424 fdesc = open(cachefile, O_RDWR);
429 strln = strlen(
args.text);
430 ast_debug(1,
"line length : %d\n", strln);
431 if (write(fdesc,&strln,
sizeof(
int)) < 0) {
434 if (write(fdesc,data,strln) < 0) {
437 seekpos = lseek(fdesc, 0, SEEK_CUR);
438 ast_debug(1,
"Seek position : %d\n", seekpos);
441 if (read(fdesc,&strln,
sizeof(
int)) !=
sizeof(
int)) {
444 ast_debug(1,
"Cache file exists, strln=%d, strlen=%d\n", strln, (
int)strlen(
args.text));
445 if (strlen(
args.text) == strln) {
447 if (read(fdesc,&bigstring,strln) != strln) {
450 bigstring[strln] = 0;
451 if (strcmp(bigstring,
args.text) == 0) {
462 if (readcache == 1) {
467 ast_debug(1,
"Passing text to festival...\n");
468 fs = fdopen(dup(fd),
"wb");
470 fprintf(fs,
"%s", festivalcommand);
476 if (writecache == 1) {
477 ast_debug(1,
"Writing result to cache...\n");
478 while ((strln = read(fd, buffer, 16384)) != 0) {
479 if (write(fdesc,buffer,strln) < 0) {
485 fd = open(cachefile, O_RDWR);
486 lseek(fd, seekpos, SEEK_SET);
489 ast_debug(1,
"Passing data to channel...\n");
495 for (n = 0; n < 3; ) {
496 read_data = read(fd, ack + n, 3 - n);
500 if (read_data == -1) {
509 if (strcmp(ack,
"WV\n") == 0) {
516 }
else if (strcmp(ack,
"LP\n") == 0) {
519 waveform[filesize] =
'\0';
523 }
else if (strcmp(ack,
"ER\n") == 0) {
528 }
while (strcmp(ack,
"OK\n") != 0);
union ast_frame_subclass subclass
static int unload_module(void)
Main Channel structure associated with a channel.
#define AST_MODULE_INFO_STANDARD(keystr, desc)
Asterisk locking-related definitions:
Asterisk main include file. File version handling, generic pbx functions.
const char * ast_variable_retrieve(const struct ast_config *config, const char *category, const char *variable)
Gets a variable.
int ast_safe_fork(int stop_reaper)
Common routine to safely fork without a chance of a signal handler firing badly in the child...
#define ast_alloca(size)
call __builtin_alloca to ensure we get gcc builtin semantics
int ast_indicate(struct ast_channel *chan, int condition)
Indicates condition of channel.
static int festival_exec(struct ast_channel *chan, const char *vdata)
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application's arguments.
void MD5Final(unsigned char digest[16], struct MD5Context *context)
struct ast_frame * ast_read(struct ast_channel *chan)
Reads a frame.
Configuration File Parser.
Generic File Format Support. Should be included by clients of the file handling routines. File service providers should instead include mod_format.h.
int ast_unregister_application(const char *app)
Unregister an application.
void ast_config_destroy(struct ast_config *config)
Destroys a config.
static int send_waveform_to_channel(struct ast_channel *chan, char *waveform, int length, char *intkeys)
void MD5Init(struct MD5Context *context)
int ast_set_write_format(struct ast_channel *chan, format_t format)
Sets write format on channel chan Set write format for channel to whichever component of "format" is ...
#define ast_debug(level,...)
Log a DEBUG message.
General Asterisk PBX channel definitions.
#define AST_FRIENDLY_OFFSET
Offset into a frame's data buffer.
#define ast_config_load(filename, flags)
Load a config file.
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Asterisk architecture endianess compatibility definitions.
Core PBX routines and definitions.
int ast_set_priority(int)
We set ourselves to a high priority, that we might pre-empt everything else. If your PBX has heavy ac...
void MD5Update(struct MD5Context *context, unsigned char const *buf, unsigned len)
#define ast_strdupa(s)
duplicate a string in memory from the stack
int attribute_pure ast_true(const char *val)
Make sure something is true. Determine if a string containing a boolean value is "true". This function checks to see whether a string passed to it is an indication of an "true" value. It checks to see if the string is "yes", "true", "y", "t", "on" or "1".
enum ast_channel_state _state
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
void ast_close_fds_above_n(int n)
Common routine for child processes, to close all fds prior to exec(2)
int ast_write(struct ast_channel *chan, struct ast_frame *frame)
Write a frame to a channel This function writes the given frame to the indicated channel.
Structure used to handle boolean flags.
struct hostent * ast_gethostbyname(const char *host, struct ast_hostent *hp)
Thread-safe gethostbyname function to use in Asterisk.
#define AST_FORMAT_SLINEAR
int ast_waitfor(struct ast_channel *chan, int ms)
Wait for input on a channel.
static unsigned char * buff
#define ast_realloc(a, b)
int ast_answer(struct ast_channel *chan)
Answer a channel.
Application convenience functions, designed to give consistent look and feel to Asterisk apps...
Data structure associated with a single frame of data.
#define AST_APP_ARG(name)
Define an application argument.
enum ast_frame_type frametype
static int load_module(void)
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the 'standard' argument separation process for an application.
#define CONFIG_STATUS_FILEINVALID
#define ASTERISK_GPL_KEY
The text the key() function should return.
Asterisk module definitions.
int ast_stopstream(struct ast_channel *c)
Stops a stream.
#define ast_register_application_xml(app, execute)
Register an application using XML documentation.
#define ASTERISK_FILE_VERSION(file, version)
Register/unregister a source code file with the core.
#define ast_opt_high_priority
static char * socket_receive_file_to_buff(int fd, int *size)
static int send_waveform_to_fd(char *waveform, int length, int fd)