2002-04-27 12:57:37 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library 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
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
2012-11-03 20:38:00 +00:00
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
2002-04-27 12:57:37 +00:00
|
|
|
*/
|
|
|
|
/*************************************************************************/
|
|
|
|
/* */
|
|
|
|
/* Centre for Speech Technology Research */
|
|
|
|
/* University of Edinburgh, UK */
|
|
|
|
/* Copyright (c) 1999 */
|
|
|
|
/* All Rights Reserved. */
|
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to use and distribute */
|
|
|
|
/* this software and its documentation without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of this work, and to */
|
|
|
|
/* permit persons to whom this work is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* 1. The code must retain the above copyright notice, this list of */
|
|
|
|
/* conditions and the following disclaimer. */
|
|
|
|
/* 2. Any modifications must be clearly marked as such. */
|
|
|
|
/* 3. Original authors' names are not deleted. */
|
|
|
|
/* 4. The authors' names are not used to endorse or promote products */
|
|
|
|
/* derived from this software without specific prior written */
|
|
|
|
/* permission. */
|
|
|
|
/* */
|
|
|
|
/* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
|
|
|
|
/* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
|
|
|
|
/* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
|
|
|
|
/* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
|
|
|
|
/* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
|
|
|
|
/* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
|
|
|
|
/* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
|
|
|
|
/* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
|
|
|
|
/* THIS SOFTWARE. */
|
|
|
|
/* */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* Author : Alan W Black (awb@cstr.ed.ac.uk) */
|
|
|
|
/* Date : March 1999 */
|
|
|
|
/*-----------------------------------------------------------------------*/
|
|
|
|
/* */
|
|
|
|
/* Client end of Festival server API in C designed specifically for */
|
|
|
|
/* Galaxy Communicator use though might be of use for other things */
|
|
|
|
/* */
|
|
|
|
/* This is a modified version of the standalone client as provided in */
|
|
|
|
/* festival example code: festival_client.c */
|
|
|
|
/* */
|
|
|
|
/*=======================================================================*/
|
|
|
|
|
2007-08-23 13:24:33 +00:00
|
|
|
/**
|
|
|
|
* SECTION:element-festival
|
2017-03-08 18:01:13 +00:00
|
|
|
* @title: festival
|
|
|
|
*
|
2007-08-23 13:24:33 +00:00
|
|
|
* This element connects to a
|
2019-08-23 17:56:35 +00:00
|
|
|
* [festival](http://www.festvox.org/festival/index.html) server process and
|
|
|
|
* uses it to synthesize speech. Festival need to run already in server mode,
|
|
|
|
* started as `festival --server`
|
2017-03-08 18:01:13 +00:00
|
|
|
*
|
|
|
|
* ## Example pipeline
|
2008-06-13 11:59:23 +00:00
|
|
|
* |[
|
2015-12-14 02:09:46 +00:00
|
|
|
* echo 'Hello G-Streamer!' | gst-launch-1.0 fdsrc fd=0 ! festival ! wavparse ! audioconvert ! alsasink
|
2008-06-13 11:59:23 +00:00
|
|
|
* ]|
|
2017-03-08 18:01:13 +00:00
|
|
|
*
|
2007-08-23 13:24:33 +00:00
|
|
|
*/
|
|
|
|
|
2003-06-29 19:46:13 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
2007-08-23 13:24:33 +00:00
|
|
|
|
2008-07-04 16:06:09 +00:00
|
|
|
#include <glib.h> /* Needed for G_OS_XXXX macros */
|
|
|
|
|
2002-04-27 12:57:37 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2008-07-24 00:32:37 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_UNISTD_H
|
2002-04-27 12:57:37 +00:00
|
|
|
#include <unistd.h>
|
2008-07-24 00:32:37 +00:00
|
|
|
#endif
|
|
|
|
|
2002-04-27 12:57:37 +00:00
|
|
|
#include <ctype.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/types.h>
|
2008-07-04 16:06:09 +00:00
|
|
|
#ifdef G_OS_WIN32
|
|
|
|
#include <winsock2.h>
|
|
|
|
#include <ws2tcpip.h>
|
|
|
|
#else
|
2002-04-27 12:57:37 +00:00
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <netdb.h>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <arpa/inet.h>
|
2008-07-04 16:06:09 +00:00
|
|
|
#endif
|
2002-04-27 12:57:37 +00:00
|
|
|
|
|
|
|
#include "gstfestival.h"
|
2003-07-06 20:49:52 +00:00
|
|
|
#include <gst/audio/audio.h>
|
2002-04-27 12:57:37 +00:00
|
|
|
|
2007-08-23 13:24:33 +00:00
|
|
|
GST_DEBUG_CATEGORY_STATIC (festival_debug);
|
|
|
|
#define GST_CAT_DEFAULT festival_debug
|
|
|
|
|
2007-09-24 10:53:37 +00:00
|
|
|
static void gst_festival_finalize (GObject * object);
|
|
|
|
|
2012-07-04 07:14:35 +00:00
|
|
|
static GstFlowReturn gst_festival_chain (GstPad * pad, GstObject * parent,
|
|
|
|
GstBuffer * buf);
|
2017-12-20 04:13:34 +00:00
|
|
|
static gboolean gst_festival_src_query (GstPad * pad, GstObject * parent,
|
|
|
|
GstQuery * query);
|
2005-09-05 17:20:29 +00:00
|
|
|
static GstStateChangeReturn gst_festival_change_state (GstElement * element,
|
|
|
|
GstStateChange transition);
|
2002-04-27 12:57:37 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
static FT_Info *festival_default_info (void);
|
|
|
|
static char *socket_receive_file_to_buff (int fd, int *size);
|
|
|
|
static char *client_accept_s_expr (int fd);
|
2002-04-27 12:57:37 +00:00
|
|
|
|
2003-12-22 01:47:09 +00:00
|
|
|
static GstStaticPadTemplate sink_template_factory =
|
2007-08-23 13:24:33 +00:00
|
|
|
GST_STATIC_PAD_TEMPLATE ("sink",
|
2004-03-14 22:34:33 +00:00
|
|
|
GST_PAD_SINK,
|
|
|
|
GST_PAD_ALWAYS,
|
2012-09-11 14:07:02 +00:00
|
|
|
GST_STATIC_CAPS ("text/x-raw, format=(string)utf8")
|
2004-03-14 22:34:33 +00:00
|
|
|
);
|
2002-04-27 12:57:37 +00:00
|
|
|
|
2003-12-22 01:47:09 +00:00
|
|
|
static GstStaticPadTemplate src_template_factory =
|
2007-08-23 13:24:33 +00:00
|
|
|
GST_STATIC_PAD_TEMPLATE ("src",
|
2004-03-14 22:34:33 +00:00
|
|
|
GST_PAD_SRC,
|
|
|
|
GST_PAD_ALWAYS,
|
2007-08-23 13:24:33 +00:00
|
|
|
GST_STATIC_CAPS ("audio/x-wav")
|
2004-03-14 22:34:33 +00:00
|
|
|
);
|
2002-04-27 12:57:37 +00:00
|
|
|
|
|
|
|
/* Festival signals and args */
|
2004-03-14 22:34:33 +00:00
|
|
|
enum
|
|
|
|
{
|
2002-04-27 12:57:37 +00:00
|
|
|
/* FILL ME */
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
enum
|
|
|
|
{
|
2015-04-27 09:55:13 +00:00
|
|
|
PROP_0
|
2004-05-21 22:39:30 +00:00
|
|
|
/* FILL ME */
|
2002-04-27 12:57:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*static guint gst_festival_signals[LAST_SIGNAL] = { 0 }; */
|
|
|
|
|
2012-07-04 07:14:35 +00:00
|
|
|
G_DEFINE_TYPE (GstFestival, gst_festival, GST_TYPE_ELEMENT)
|
2002-04-27 12:57:37 +00:00
|
|
|
|
2012-07-04 07:14:35 +00:00
|
|
|
static void gst_festival_class_init (GstFestivalClass * klass)
|
2002-04-27 12:57:37 +00:00
|
|
|
{
|
2007-09-24 10:53:37 +00:00
|
|
|
GObjectClass *gobject_class;
|
2002-04-27 12:57:37 +00:00
|
|
|
GstElementClass *gstelement_class;
|
|
|
|
|
2007-09-24 10:53:37 +00:00
|
|
|
gobject_class = G_OBJECT_CLASS (klass);
|
|
|
|
gstelement_class = GST_ELEMENT_CLASS (klass);
|
2002-04-27 12:57:37 +00:00
|
|
|
|
2007-09-24 10:53:37 +00:00
|
|
|
gobject_class->finalize = GST_DEBUG_FUNCPTR (gst_festival_finalize);
|
|
|
|
gstelement_class->change_state =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_festival_change_state);
|
2012-07-04 07:14:35 +00:00
|
|
|
|
|
|
|
/* register pads */
|
2016-03-04 06:50:26 +00:00
|
|
|
gst_element_class_add_static_pad_template (gstelement_class,
|
|
|
|
&sink_template_factory);
|
|
|
|
gst_element_class_add_static_pad_template (gstelement_class,
|
|
|
|
&src_template_factory);
|
2012-07-04 07:14:35 +00:00
|
|
|
|
2012-10-17 16:34:26 +00:00
|
|
|
gst_element_class_set_static_metadata (gstelement_class,
|
2012-07-04 07:14:35 +00:00
|
|
|
"Festival Text-to-Speech synthesizer", "Filter/Effect/Audio",
|
|
|
|
"Synthesizes plain text into audio",
|
2012-07-10 10:10:28 +00:00
|
|
|
"Wim Taymans <wim.taymans@gmail.com>");
|
2002-04-27 12:57:37 +00:00
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
static void
|
|
|
|
gst_festival_init (GstFestival * festival)
|
2002-04-27 12:57:37 +00:00
|
|
|
{
|
2004-03-14 22:34:33 +00:00
|
|
|
festival->sinkpad =
|
2007-06-22 10:46:33 +00:00
|
|
|
gst_pad_new_from_static_template (&sink_template_factory, "sink");
|
2002-04-27 12:57:37 +00:00
|
|
|
gst_pad_set_chain_function (festival->sinkpad, gst_festival_chain);
|
|
|
|
gst_element_add_pad (GST_ELEMENT (festival), festival->sinkpad);
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
festival->srcpad =
|
2007-06-22 10:46:33 +00:00
|
|
|
gst_pad_new_from_static_template (&src_template_factory, "src");
|
2017-12-20 04:13:34 +00:00
|
|
|
gst_pad_set_query_function (festival->srcpad, gst_festival_src_query);
|
2002-04-27 12:57:37 +00:00
|
|
|
gst_element_add_pad (GST_ELEMENT (festival), festival->srcpad);
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
festival->info = festival_default_info ();
|
2002-04-27 12:57:37 +00:00
|
|
|
}
|
|
|
|
|
2007-09-24 10:53:37 +00:00
|
|
|
static void
|
|
|
|
gst_festival_finalize (GObject * object)
|
|
|
|
{
|
|
|
|
GstFestival *festival = GST_FESTIVAL (object);
|
|
|
|
|
|
|
|
g_free (festival->info);
|
|
|
|
|
2012-07-04 07:14:35 +00:00
|
|
|
G_OBJECT_CLASS (gst_festival_parent_class)->finalize (object);
|
2007-09-24 10:53:37 +00:00
|
|
|
}
|
|
|
|
|
2007-08-23 13:24:33 +00:00
|
|
|
static gboolean
|
|
|
|
read_response (GstFestival * festival)
|
2002-04-27 12:57:37 +00:00
|
|
|
{
|
|
|
|
char ack[4];
|
2007-08-23 13:24:33 +00:00
|
|
|
char *data;
|
|
|
|
int filesize;
|
|
|
|
int fd;
|
2002-04-27 12:57:37 +00:00
|
|
|
int n;
|
2007-08-23 13:24:33 +00:00
|
|
|
gboolean ret = TRUE;
|
|
|
|
|
|
|
|
fd = festival->info->server_fd;
|
|
|
|
do {
|
|
|
|
for (n = 0; n < 3;)
|
|
|
|
n += read (fd, ack + n, 3 - n);
|
|
|
|
ack[3] = '\0';
|
|
|
|
GST_DEBUG_OBJECT (festival, "got response %s", ack);
|
|
|
|
if (strcmp (ack, "WV\n") == 0) {
|
|
|
|
GstBuffer *buffer;
|
|
|
|
|
|
|
|
/* receive a waveform */
|
|
|
|
data = socket_receive_file_to_buff (fd, &filesize);
|
|
|
|
GST_DEBUG_OBJECT (festival, "received %d bytes of waveform data",
|
|
|
|
filesize);
|
|
|
|
|
|
|
|
/* push contents as a buffer */
|
2012-07-04 07:14:35 +00:00
|
|
|
buffer = gst_buffer_new_wrapped (data, filesize);
|
2007-08-23 13:24:33 +00:00
|
|
|
GST_BUFFER_TIMESTAMP (buffer) = GST_CLOCK_TIME_NONE;
|
|
|
|
gst_pad_push (festival->srcpad, buffer);
|
|
|
|
|
|
|
|
} else if (strcmp (ack, "LP\n") == 0) {
|
|
|
|
/* receive an s-expr */
|
|
|
|
data = client_accept_s_expr (fd);
|
|
|
|
GST_DEBUG_OBJECT (festival, "received s-expression: %s", data);
|
|
|
|
g_free (data);
|
|
|
|
} else if (strcmp (ack, "ER\n") == 0) {
|
|
|
|
/* server got an error */
|
|
|
|
GST_ELEMENT_ERROR (festival,
|
|
|
|
LIBRARY,
|
|
|
|
FAILED,
|
|
|
|
("Festival speech server returned an error"),
|
|
|
|
("Make sure you have voices/languages installed"));
|
|
|
|
ret = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
} while (strcmp (ack, "OK\n") != 0);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstFlowReturn
|
2012-07-04 07:14:35 +00:00
|
|
|
gst_festival_chain (GstPad * pad, GstObject * parent, GstBuffer * buf)
|
2007-08-23 13:24:33 +00:00
|
|
|
{
|
|
|
|
GstFlowReturn ret = GST_FLOW_OK;
|
2002-04-27 12:57:37 +00:00
|
|
|
GstFestival *festival;
|
2012-07-04 07:14:35 +00:00
|
|
|
GstMapInfo info;
|
2007-08-23 13:24:33 +00:00
|
|
|
guint8 *p, *ep;
|
2012-01-23 12:56:02 +00:00
|
|
|
gint f;
|
2007-08-23 13:24:33 +00:00
|
|
|
FILE *fd;
|
2002-04-27 12:57:37 +00:00
|
|
|
|
2012-07-04 07:14:35 +00:00
|
|
|
festival = GST_FESTIVAL (parent);
|
2002-04-27 12:57:37 +00:00
|
|
|
|
2012-07-15 11:27:12 +00:00
|
|
|
GST_LOG_OBJECT (festival, "Got text buffer, %" G_GSIZE_FORMAT " bytes",
|
2012-07-04 07:14:35 +00:00
|
|
|
gst_buffer_get_size (buf));
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2012-01-23 12:56:02 +00:00
|
|
|
f = dup (festival->info->server_fd);
|
|
|
|
if (f < 0)
|
|
|
|
goto fail_open;
|
|
|
|
fd = fdopen (f, "wb");
|
|
|
|
if (fd == NULL) {
|
|
|
|
close (f);
|
|
|
|
goto fail_open;
|
|
|
|
}
|
2002-04-27 12:57:37 +00:00
|
|
|
|
|
|
|
/* Copy text over to server, escaping any quotes */
|
2004-12-15 03:59:26 +00:00
|
|
|
fprintf (fd, "(Parameter.set 'Audio_Required_Rate 16000)\n");
|
2007-08-23 13:24:33 +00:00
|
|
|
fflush (fd);
|
|
|
|
GST_DEBUG_OBJECT (festival, "issued Parameter.set command");
|
|
|
|
if (read_response (festival) == FALSE) {
|
2011-05-19 21:20:07 +00:00
|
|
|
fclose (fd);
|
2012-01-23 12:56:02 +00:00
|
|
|
goto fail_read;
|
2007-08-23 13:24:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fprintf (fd, "(tts_textall \"");
|
2012-07-10 10:10:28 +00:00
|
|
|
gst_buffer_map (buf, &info, GST_MAP_READ);
|
2012-07-04 07:14:35 +00:00
|
|
|
p = info.data;
|
2012-07-10 10:10:28 +00:00
|
|
|
ep = p + info.size;
|
2007-08-23 13:24:33 +00:00
|
|
|
for (; p < ep && (*p != '\0'); p++) {
|
|
|
|
if ((*p == '"') || (*p == '\\')) {
|
2004-03-14 22:34:33 +00:00
|
|
|
putc ('\\', fd);
|
2007-08-23 13:24:33 +00:00
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
putc (*p, fd);
|
2002-04-27 12:57:37 +00:00
|
|
|
}
|
2004-03-14 22:34:33 +00:00
|
|
|
fprintf (fd, "\" \"%s\")\n", festival->info->text_mode);
|
|
|
|
fclose (fd);
|
2012-07-10 10:10:28 +00:00
|
|
|
gst_buffer_unmap (buf, &info);
|
2002-04-27 12:57:37 +00:00
|
|
|
|
2007-08-23 13:24:33 +00:00
|
|
|
GST_DEBUG_OBJECT (festival, "issued tts_textall command");
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2007-08-23 13:24:33 +00:00
|
|
|
/* Read back info from server */
|
|
|
|
if (read_response (festival) == FALSE)
|
2012-01-23 12:56:02 +00:00
|
|
|
goto fail_read;
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2007-08-23 13:24:33 +00:00
|
|
|
out:
|
2002-04-27 12:57:37 +00:00
|
|
|
gst_buffer_unref (buf);
|
2007-08-23 13:24:33 +00:00
|
|
|
return ret;
|
2012-01-23 12:56:02 +00:00
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
fail_open:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_ERROR (festival, RESOURCE, OPEN_WRITE, (NULL), (NULL));
|
|
|
|
ret = GST_FLOW_ERROR;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
fail_read:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_ERROR (festival, RESOURCE, READ, (NULL), (NULL));
|
|
|
|
ret = GST_FLOW_ERROR;
|
|
|
|
goto out;
|
|
|
|
}
|
2002-04-27 12:57:37 +00:00
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
static FT_Info *
|
2002-04-27 12:57:37 +00:00
|
|
|
festival_default_info (void)
|
|
|
|
{
|
|
|
|
FT_Info *info;
|
2004-03-14 22:34:33 +00:00
|
|
|
|
|
|
|
info = (FT_Info *) malloc (1 * sizeof (FT_Info));
|
|
|
|
|
2002-04-27 12:57:37 +00:00
|
|
|
info->server_host = FESTIVAL_DEFAULT_SERVER_HOST;
|
|
|
|
info->server_port = FESTIVAL_DEFAULT_SERVER_PORT;
|
|
|
|
info->text_mode = FESTIVAL_DEFAULT_TEXT_MODE;
|
|
|
|
|
|
|
|
info->server_fd = -1;
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2002-04-27 12:57:37 +00:00
|
|
|
return info;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
festival_socket_open (const char *host, int port)
|
2004-03-14 22:34:33 +00:00
|
|
|
{
|
|
|
|
/* Return an FD to a remote server */
|
2002-04-27 12:57:37 +00:00
|
|
|
struct sockaddr_in serv_addr;
|
|
|
|
struct hostent *serverhost;
|
|
|
|
int fd;
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
fd = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
2002-04-27 12:57:37 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
if (fd < 0) {
|
|
|
|
fprintf (stderr, "festival_client: can't get socket\n");
|
2002-04-27 12:57:37 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2004-03-14 22:34:33 +00:00
|
|
|
memset (&serv_addr, 0, sizeof (serv_addr));
|
|
|
|
if ((serv_addr.sin_addr.s_addr = inet_addr (host)) == -1) {
|
2002-04-27 12:57:37 +00:00
|
|
|
/* its a name rather than an ipnum */
|
2004-03-14 22:34:33 +00:00
|
|
|
serverhost = gethostbyname (host);
|
|
|
|
if (serverhost == (struct hostent *) 0) {
|
|
|
|
fprintf (stderr, "festival_client: gethostbyname failed\n");
|
2014-04-08 11:20:40 +00:00
|
|
|
close (fd);
|
2002-04-27 12:57:37 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2004-03-14 22:34:33 +00:00
|
|
|
memmove (&serv_addr.sin_addr, serverhost->h_addr, serverhost->h_length);
|
2002-04-27 12:57:37 +00:00
|
|
|
}
|
|
|
|
serv_addr.sin_family = AF_INET;
|
2004-03-14 22:34:33 +00:00
|
|
|
serv_addr.sin_port = htons (port);
|
2002-04-27 12:57:37 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
if (connect (fd, (struct sockaddr *) &serv_addr, sizeof (serv_addr)) != 0) {
|
|
|
|
fprintf (stderr, "festival_client: connect to server failed\n");
|
2014-04-08 11:20:40 +00:00
|
|
|
close (fd);
|
2002-04-27 12:57:37 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return fd;
|
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
static char *
|
2002-04-27 12:57:37 +00:00
|
|
|
client_accept_s_expr (int fd)
|
|
|
|
{
|
|
|
|
/* Read s-expression from server, as a char * */
|
|
|
|
char *expr;
|
|
|
|
int filesize;
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
expr = socket_receive_file_to_buff (fd, &filesize);
|
2002-04-27 12:57:37 +00:00
|
|
|
expr[filesize] = '\0';
|
|
|
|
|
|
|
|
return expr;
|
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
static char *
|
2002-04-27 12:57:37 +00:00
|
|
|
socket_receive_file_to_buff (int fd, int *size)
|
|
|
|
{
|
|
|
|
/* Receive file (probably a waveform file) from socket using */
|
|
|
|
/* Festival key stuff technique, but long winded I know, sorry */
|
|
|
|
/* but will receive any file without closeing the stream or */
|
|
|
|
/* using OOB data */
|
2005-12-16 21:55:18 +00:00
|
|
|
static const char file_stuff_key[] = "ft_StUfF_key"; /* must == Festival's key */
|
2002-04-27 12:57:37 +00:00
|
|
|
char *buff;
|
|
|
|
int bufflen;
|
2004-03-14 22:34:33 +00:00
|
|
|
int n, k, i;
|
2002-04-27 12:57:37 +00:00
|
|
|
char c;
|
|
|
|
|
|
|
|
bufflen = 1024;
|
2007-08-23 13:24:33 +00:00
|
|
|
buff = (char *) g_malloc (bufflen);
|
2004-03-14 22:34:33 +00:00
|
|
|
*size = 0;
|
|
|
|
|
|
|
|
for (k = 0; file_stuff_key[k] != '\0';) {
|
|
|
|
n = read (fd, &c, 1);
|
|
|
|
if (n == 0)
|
2004-03-15 19:32:27 +00:00
|
|
|
break; /* hit stream eof before end of file */
|
2007-08-23 13:24:33 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
if ((*size) + k + 1 >= bufflen) {
|
2002-04-27 12:57:37 +00:00
|
|
|
/* +1 so you can add a NULL if you want */
|
2004-03-14 22:34:33 +00:00
|
|
|
bufflen += bufflen / 4;
|
2007-08-23 13:24:33 +00:00
|
|
|
buff = (char *) g_realloc (buff, bufflen);
|
2002-04-27 12:57:37 +00:00
|
|
|
}
|
|
|
|
if (file_stuff_key[k] == c)
|
|
|
|
k++;
|
2004-03-14 22:34:33 +00:00
|
|
|
else if ((c == 'X') && (file_stuff_key[k + 1] == '\0')) {
|
2002-04-27 12:57:37 +00:00
|
|
|
/* It looked like the key but wasn't */
|
2004-03-14 22:34:33 +00:00
|
|
|
for (i = 0; i < k; i++, (*size)++)
|
2004-03-15 19:32:27 +00:00
|
|
|
buff[*size] = file_stuff_key[i];
|
2004-03-14 22:34:33 +00:00
|
|
|
k = 0;
|
2002-04-27 12:57:37 +00:00
|
|
|
/* omit the stuffed 'X' */
|
2004-03-14 22:34:33 +00:00
|
|
|
} else {
|
|
|
|
for (i = 0; i < k; i++, (*size)++)
|
2004-03-15 19:32:27 +00:00
|
|
|
buff[*size] = file_stuff_key[i];
|
2004-03-14 22:34:33 +00:00
|
|
|
k = 0;
|
2002-04-27 12:57:37 +00:00
|
|
|
buff[*size] = c;
|
|
|
|
(*size)++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return buff;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************/
|
|
|
|
/* Public Functions to this API */
|
|
|
|
/***********************************************************************/
|
|
|
|
|
|
|
|
static gboolean
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_festival_open (GstFestival * festival)
|
2002-04-27 12:57:37 +00:00
|
|
|
{
|
|
|
|
/* Open socket to server */
|
|
|
|
if (festival->info == NULL)
|
2004-03-14 22:34:33 +00:00
|
|
|
festival->info = festival_default_info ();
|
2002-04-27 12:57:37 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
festival->info->server_fd =
|
|
|
|
festival_socket_open (festival->info->server_host,
|
|
|
|
festival->info->server_port);
|
2008-07-09 12:13:09 +00:00
|
|
|
if (festival->info->server_fd == -1) {
|
|
|
|
GST_ERROR
|
|
|
|
("Could not talk to festival server (no server running or wrong host/port?)");
|
2002-04-27 12:57:37 +00:00
|
|
|
return FALSE;
|
2008-07-09 12:13:09 +00:00
|
|
|
}
|
2010-05-13 12:41:08 +00:00
|
|
|
GST_OBJECT_FLAG_SET (festival, GST_FESTIVAL_OPEN);
|
2002-04-27 12:57:37 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_festival_close (GstFestival * festival)
|
2002-04-27 12:57:37 +00:00
|
|
|
{
|
|
|
|
if (festival->info == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (festival->info->server_fd != -1)
|
2004-03-14 22:34:33 +00:00
|
|
|
close (festival->info->server_fd);
|
2010-05-13 12:41:08 +00:00
|
|
|
GST_OBJECT_FLAG_UNSET (festival, GST_FESTIVAL_OPEN);
|
2002-04-27 12:57:37 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2005-09-05 17:20:29 +00:00
|
|
|
static GstStateChangeReturn
|
|
|
|
gst_festival_change_state (GstElement * element, GstStateChange transition)
|
2002-04-27 12:57:37 +00:00
|
|
|
{
|
2005-09-05 17:20:29 +00:00
|
|
|
g_return_val_if_fail (GST_IS_FESTIVAL (element), GST_STATE_CHANGE_FAILURE);
|
2002-04-27 12:57:37 +00:00
|
|
|
|
|
|
|
if (GST_STATE_PENDING (element) == GST_STATE_NULL) {
|
2010-05-13 12:42:48 +00:00
|
|
|
if (GST_OBJECT_FLAG_IS_SET (element, GST_FESTIVAL_OPEN)) {
|
2010-05-13 12:41:08 +00:00
|
|
|
GST_DEBUG ("Closing connection ");
|
2010-05-13 12:42:48 +00:00
|
|
|
gst_festival_close (GST_FESTIVAL (element));
|
|
|
|
}
|
2002-04-27 12:57:37 +00:00
|
|
|
} else {
|
renamed GST_FLAGS macros to GST_OBJECT_FLAGS moved bitshift from macro to enum definition
Original commit message from CVS:
* examples/indexing/indexmpeg.c: (main):
* ext/artsd/gstartsdsink.c: (gst_artsdsink_open_audio),
(gst_artsdsink_close_audio), (gst_artsdsink_change_state):
* ext/artsd/gstartsdsink.h:
* ext/audiofile/gstafparse.c: (gst_afparse_open_file),
(gst_afparse_close_file):
* ext/audiofile/gstafparse.h:
* ext/audiofile/gstafsink.c: (gst_afsink_open_file),
(gst_afsink_close_file), (gst_afsink_chain),
(gst_afsink_change_state):
* ext/audiofile/gstafsink.h:
* ext/audiofile/gstafsrc.c: (gst_afsrc_open_file),
(gst_afsrc_close_file), (gst_afsrc_change_state):
* ext/audiofile/gstafsrc.h:
* ext/cdaudio/gstcdaudio.c: (gst_cdaudio_init):
* ext/directfb/directfbvideosink.c: (gst_directfbvideosink_init):
* ext/dts/gstdtsdec.c: (gst_dtsdec_init):
* ext/jack/gstjack.h:
* ext/jack/gstjackbin.c: (gst_jack_bin_init),
(gst_jack_bin_change_state):
* ext/musepack/gstmusepackdec.c: (gst_musepackdec_init):
* ext/musicbrainz/gsttrm.c: (gst_musicbrainz_init):
* ext/nas/nassink.c: (gst_nassink_open_audio),
(gst_nassink_close_audio), (gst_nassink_change_state):
* ext/nas/nassink.h:
* ext/polyp/polypsink.c: (gst_polypsink_init):
* ext/sdl/sdlvideosink.c: (gst_sdlvideosink_change_state):
* ext/sdl/sdlvideosink.h:
* ext/smoothwave/gstsmoothwave.c: (gst_smoothwave_init):
* ext/sndfile/gstsf.c: (gst_sf_set_property),
(gst_sf_change_state), (gst_sf_release_request_pad),
(gst_sf_open_file), (gst_sf_close_file), (gst_sf_loop):
* ext/sndfile/gstsf.h:
* ext/swfdec/gstswfdec.c: (gst_swfdec_init):
* ext/tarkin/gsttarkindec.c: (gst_tarkindec_init):
* gst/apetag/apedemux.c: (gst_ape_demux_init):
* gst/cdxaparse/gstcdxaparse.c: (gst_cdxaparse_init):
* gst/cdxaparse/gstcdxastrip.c: (gst_cdxastrip_init):
* gst/festival/gstfestival.c: (gst_festival_change_state):
* gst/festival/gstfestival.h:
* gst/mpeg2sub/gstmpeg2subt.c: (gst_mpeg2subt_init):
* gst/multifilesink/gstmultifilesink.c: (gst_multifilesink_init),
(gst_multifilesink_set_location), (gst_multifilesink_open_file),
(gst_multifilesink_close_file), (gst_multifilesink_next_file),
(gst_multifilesink_pad_query), (gst_multifilesink_handle_event),
(gst_multifilesink_chain), (gst_multifilesink_change_state):
* gst/multifilesink/gstmultifilesink.h:
* gst/videodrop/gstvideodrop.c: (gst_videodrop_init):
* sys/cdrom/gstcdplayer.c: (cdplayer_init):
* sys/dxr3/dxr3audiosink.c: (dxr3audiosink_init),
(dxr3audiosink_open), (dxr3audiosink_close),
(dxr3audiosink_chain_pcm), (dxr3audiosink_chain_ac3),
(dxr3audiosink_change_state):
* sys/dxr3/dxr3audiosink.h:
* sys/dxr3/dxr3spusink.c: (dxr3spusink_init), (dxr3spusink_open),
(dxr3spusink_close), (dxr3spusink_chain),
(dxr3spusink_change_state):
* sys/dxr3/dxr3spusink.h:
* sys/dxr3/dxr3videosink.c: (dxr3videosink_init),
(dxr3videosink_open), (dxr3videosink_close),
(dxr3videosink_write_data), (dxr3videosink_change_state):
* sys/dxr3/dxr3videosink.h:
* sys/glsink/glimagesink.c: (gst_glimagesink_init):
* sys/qcam/gstqcamsrc.c: (gst_qcamsrc_change_state),
(gst_qcamsrc_open), (gst_qcamsrc_close):
* sys/qcam/gstqcamsrc.h:
* sys/v4l2/gstv4l2src.c: (gst_v4l2src_init):
* sys/vcd/vcdsrc.c: (gst_vcdsrc_set_property), (gst_vcdsrc_get),
(gst_vcdsrc_open_file), (gst_vcdsrc_close_file),
(gst_vcdsrc_change_state), (gst_vcdsrc_recalculate):
* sys/vcd/vcdsrc.h:
renamed GST_FLAGS macros to GST_OBJECT_FLAGS
moved bitshift from macro to enum definition
2005-10-12 14:29:55 +00:00
|
|
|
if (!GST_OBJECT_FLAG_IS_SET (element, GST_FESTIVAL_OPEN)) {
|
2010-05-13 12:41:08 +00:00
|
|
|
GST_DEBUG ("Opening connection ");
|
2002-04-27 12:57:37 +00:00
|
|
|
if (!gst_festival_open (GST_FESTIVAL (element)))
|
2005-09-05 17:20:29 +00:00
|
|
|
return GST_STATE_CHANGE_FAILURE;
|
2002-04-27 12:57:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-04 07:14:35 +00:00
|
|
|
if (GST_ELEMENT_CLASS (gst_festival_parent_class)->change_state)
|
|
|
|
return GST_ELEMENT_CLASS (gst_festival_parent_class)->change_state (element,
|
|
|
|
transition);
|
2002-04-27 12:57:37 +00:00
|
|
|
|
2005-09-05 17:20:29 +00:00
|
|
|
return GST_STATE_CHANGE_SUCCESS;
|
2002-04-27 12:57:37 +00:00
|
|
|
}
|
|
|
|
|
2017-12-20 04:13:34 +00:00
|
|
|
static gboolean
|
|
|
|
gst_festival_src_query (GstPad * pad, GstObject * parent, GstQuery * query)
|
|
|
|
{
|
|
|
|
switch (GST_QUERY_TYPE (query)) {
|
|
|
|
case GST_QUERY_POSITION:
|
|
|
|
/* Not supported */
|
|
|
|
return FALSE;
|
|
|
|
case GST_QUERY_DURATION:
|
|
|
|
gst_query_set_duration (query, GST_FORMAT_BYTES, -1);
|
|
|
|
return TRUE;
|
|
|
|
case GST_QUERY_SEEKING:
|
|
|
|
gst_query_set_seeking (query, GST_FORMAT_BYTES, FALSE, 0, -1);
|
|
|
|
return TRUE;
|
|
|
|
case GST_QUERY_FORMATS:
|
|
|
|
gst_query_set_formats (query, 1, GST_FORMAT_BYTES);
|
|
|
|
return TRUE;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return gst_pad_query_default (pad, parent, query);
|
|
|
|
}
|
|
|
|
|
2002-04-27 12:57:37 +00:00
|
|
|
static gboolean
|
2004-03-14 22:34:33 +00:00
|
|
|
plugin_init (GstPlugin * plugin)
|
2002-04-27 12:57:37 +00:00
|
|
|
{
|
2007-08-23 13:24:33 +00:00
|
|
|
GST_DEBUG_CATEGORY_INIT (festival_debug, "festival",
|
|
|
|
0, "Festival text-to-speech synthesizer");
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
if (!gst_element_register (plugin, "festival", GST_RANK_NONE,
|
2004-03-15 19:32:27 +00:00
|
|
|
GST_TYPE_FESTIVAL))
|
2003-11-02 13:06:25 +00:00
|
|
|
return FALSE;
|
2002-04-27 12:57:37 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
|
|
|
|
GST_VERSION_MINOR,
|
2012-04-05 16:02:56 +00:00
|
|
|
festival,
|
2004-03-14 22:34:33 +00:00
|
|
|
"Synthesizes plain text into audio",
|
2006-04-01 10:09:11 +00:00
|
|
|
plugin_init, VERSION, "LGPL", GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN);
|