mirror of
https://github.com/rhasspy/espeak-ng.git
synced 2026-12-03 06:55:44 +00:00
Use espeak_ng_STATUS codes for the fifo API.
This commit is contained in:
@@ -38,6 +38,7 @@ typedef enum {
|
|||||||
ENS_OK = 0,
|
ENS_OK = 0,
|
||||||
ENS_COMPILE_ERROR = 0x100001FF,
|
ENS_COMPILE_ERROR = 0x100001FF,
|
||||||
ENS_VERSION_MISMATCH = 0x100002FF,
|
ENS_VERSION_MISMATCH = 0x100002FF,
|
||||||
|
ENS_FIFO_BUFFER_FULL = 0x100003FF,
|
||||||
} espeak_ng_STATUS;
|
} espeak_ng_STATUS;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
|
|||||||
+46
-45
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2007, Gilles Casse <gcasse@oralux.org>
|
* Copyright (C) 2007, Gilles Casse <gcasse@oralux.org>
|
||||||
* Copyright (C) 2013-2015 Reece H. Dunn
|
* Copyright (C) 2013-2016 Reece H. Dunn
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@@ -33,6 +33,8 @@
|
|||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
|
#include "espeak_ng.h"
|
||||||
|
|
||||||
#include "speech.h"
|
#include "speech.h"
|
||||||
#include "fifo.h"
|
#include "fifo.h"
|
||||||
#include "wave.h"
|
#include "wave.h"
|
||||||
@@ -50,7 +52,7 @@ static sem_t my_sem_stop_is_acknowledged;
|
|||||||
|
|
||||||
static void *say_thread(void *);
|
static void *say_thread(void *);
|
||||||
|
|
||||||
static espeak_ERROR push(t_espeak_command *the_command);
|
static espeak_ng_STATUS push(t_espeak_command *the_command);
|
||||||
static t_espeak_command *pop();
|
static t_espeak_command *pop();
|
||||||
static void init(int process_parameters);
|
static void init(int process_parameters);
|
||||||
static int node_counter = 0;
|
static int node_counter = 0;
|
||||||
@@ -87,17 +89,19 @@ void fifo_init()
|
|||||||
continue; // Restart when interrupted by handler
|
continue; // Restart when interrupted by handler
|
||||||
}
|
}
|
||||||
|
|
||||||
espeak_ERROR fifo_add_command(t_espeak_command *the_command)
|
espeak_ng_STATUS fifo_add_command(t_espeak_command *the_command)
|
||||||
{
|
{
|
||||||
int a_status = pthread_mutex_lock(&my_mutex);
|
espeak_ng_STATUS status;
|
||||||
espeak_ERROR a_error = EE_OK;
|
if ((status = pthread_mutex_lock(&my_mutex)) != ENS_OK)
|
||||||
|
return status;
|
||||||
|
|
||||||
if (!a_status) {
|
if ((status = push(the_command)) != ENS_OK)
|
||||||
a_error = push(the_command);
|
return status;
|
||||||
a_status = pthread_mutex_unlock(&my_mutex);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!a_status && !my_command_is_running && (a_error == EE_OK)) {
|
if ((status = pthread_mutex_unlock(&my_mutex)) != ENS_OK)
|
||||||
|
return status;
|
||||||
|
|
||||||
|
if (!my_command_is_running) {
|
||||||
// quit when command is actually started
|
// quit when command is actually started
|
||||||
// (for possible forthcoming 'end of command' checks)
|
// (for possible forthcoming 'end of command' checks)
|
||||||
sem_post(&my_sem_start_is_required);
|
sem_post(&my_sem_start_is_required);
|
||||||
@@ -108,28 +112,28 @@ espeak_ERROR fifo_add_command(t_espeak_command *the_command)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (a_status != 0)
|
return ENS_OK;
|
||||||
a_error = EE_INTERNAL_ERROR;
|
|
||||||
|
|
||||||
return a_error;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
espeak_ERROR fifo_add_commands(t_espeak_command *command1, t_espeak_command *command2)
|
espeak_ng_STATUS fifo_add_commands(t_espeak_command *command1, t_espeak_command *command2)
|
||||||
{
|
{
|
||||||
int a_status = pthread_mutex_lock(&my_mutex);
|
espeak_ng_STATUS status;
|
||||||
espeak_ERROR a_error = EE_OK;
|
if ((status = pthread_mutex_lock(&my_mutex)) != ENS_OK)
|
||||||
|
return status;
|
||||||
|
|
||||||
if (!a_status) {
|
if (node_counter+1 >= MAX_NODE_COUNTER)
|
||||||
if (node_counter+1 >= MAX_NODE_COUNTER)
|
return ENS_FIFO_BUFFER_FULL;
|
||||||
a_error = EE_BUFFER_FULL;
|
|
||||||
else {
|
|
||||||
push(command1);
|
|
||||||
push(command2);
|
|
||||||
}
|
|
||||||
a_status = pthread_mutex_unlock(&my_mutex);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!a_status && !my_command_is_running && (a_error == EE_OK)) {
|
if ((status = push(command1)) != ENS_OK)
|
||||||
|
return status;
|
||||||
|
|
||||||
|
if ((status = push(command2)) != ENS_OK)
|
||||||
|
return status;
|
||||||
|
|
||||||
|
if ((status = pthread_mutex_unlock(&my_mutex)) != ENS_OK)
|
||||||
|
return status;
|
||||||
|
|
||||||
|
if (!my_command_is_running) {
|
||||||
// quit when one command is actually started
|
// quit when one command is actually started
|
||||||
// (for possible forthcoming 'end of command' checks)
|
// (for possible forthcoming 'end of command' checks)
|
||||||
sem_post(&my_sem_start_is_required);
|
sem_post(&my_sem_start_is_required);
|
||||||
@@ -140,26 +144,23 @@ espeak_ERROR fifo_add_commands(t_espeak_command *command1, t_espeak_command *com
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (a_status != 0)
|
return ENS_OK;
|
||||||
a_error = EE_INTERNAL_ERROR;
|
|
||||||
|
|
||||||
return a_error;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
espeak_ERROR fifo_stop()
|
espeak_ng_STATUS fifo_stop()
|
||||||
{
|
{
|
||||||
int a_command_is_running = 0;
|
espeak_ng_STATUS status;
|
||||||
int a_status = pthread_mutex_lock(&my_mutex);
|
if ((status = pthread_mutex_lock(&my_mutex)) != ENS_OK)
|
||||||
if (a_status != 0)
|
return status;
|
||||||
return EE_INTERNAL_ERROR;
|
|
||||||
|
|
||||||
|
int a_command_is_running = 0;
|
||||||
if (my_command_is_running) {
|
if (my_command_is_running) {
|
||||||
a_command_is_running = 1;
|
a_command_is_running = 1;
|
||||||
my_stop_is_required = 1;
|
my_stop_is_required = 1;
|
||||||
}
|
}
|
||||||
a_status = pthread_mutex_unlock(&my_mutex);
|
|
||||||
if (a_status != 0)
|
if ((status = pthread_mutex_unlock(&my_mutex)) != ENS_OK)
|
||||||
return EE_INTERNAL_ERROR;
|
return status;
|
||||||
|
|
||||||
if (a_command_is_running) {
|
if (a_command_is_running) {
|
||||||
while ((sem_wait(&my_sem_stop_is_acknowledged) == -1) && errno == EINTR)
|
while ((sem_wait(&my_sem_stop_is_acknowledged) == -1) && errno == EINTR)
|
||||||
@@ -168,7 +169,7 @@ espeak_ERROR fifo_stop()
|
|||||||
|
|
||||||
my_stop_is_required = 0;
|
my_stop_is_required = 0;
|
||||||
|
|
||||||
return EE_OK;
|
return ENS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int fifo_is_busy()
|
int fifo_is_busy()
|
||||||
@@ -324,19 +325,19 @@ typedef struct t_node {
|
|||||||
static node *head = NULL;
|
static node *head = NULL;
|
||||||
static node *tail = NULL;
|
static node *tail = NULL;
|
||||||
|
|
||||||
static espeak_ERROR push(t_espeak_command *the_command)
|
static espeak_ng_STATUS push(t_espeak_command *the_command)
|
||||||
{
|
{
|
||||||
assert((!head && !tail) || (head && tail));
|
assert((!head && !tail) || (head && tail));
|
||||||
|
|
||||||
if (the_command == NULL)
|
if (the_command == NULL)
|
||||||
return EE_INTERNAL_ERROR;
|
return EINVAL;
|
||||||
|
|
||||||
if (node_counter >= MAX_NODE_COUNTER)
|
if (node_counter >= MAX_NODE_COUNTER)
|
||||||
return EE_BUFFER_FULL;
|
return ENS_FIFO_BUFFER_FULL;
|
||||||
|
|
||||||
node *n = (node *)malloc(sizeof(node));
|
node *n = (node *)malloc(sizeof(node));
|
||||||
if (n == NULL)
|
if (n == NULL)
|
||||||
return EE_INTERNAL_ERROR;
|
return ENOMEM;
|
||||||
|
|
||||||
if (head == NULL) {
|
if (head == NULL) {
|
||||||
head = n;
|
head = n;
|
||||||
@@ -353,7 +354,7 @@ static espeak_ERROR push(t_espeak_command *the_command)
|
|||||||
|
|
||||||
the_command->state = CS_PENDING;
|
the_command->state = CS_PENDING;
|
||||||
|
|
||||||
return EE_OK;
|
return ENS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static t_espeak_command *pop()
|
static t_espeak_command *pop()
|
||||||
|
|||||||
+4
-16
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2007, Gilles Casse <gcasse@oralux.org>
|
* Copyright (C) 2007, Gilles Casse <gcasse@oralux.org>
|
||||||
* Copyright (C) 2015 Reece H. Dunn
|
* Copyright (C) 2015-2016 Reece H. Dunn
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@@ -38,28 +38,16 @@ void fifo_init();
|
|||||||
//
|
//
|
||||||
// Note: this function fails if too many commands are already buffered.
|
// Note: this function fails if too many commands are already buffered.
|
||||||
// In such a case, the calling function could wait and then add again its command.
|
// In such a case, the calling function could wait and then add again its command.
|
||||||
//
|
espeak_ng_STATUS fifo_add_command(t_espeak_command *c);
|
||||||
// Return: EE_OK: operation achieved
|
|
||||||
// EE_BUFFER_FULL: the command can not be buffered;
|
|
||||||
// you may try after a while to call the function again.
|
|
||||||
// EE_INTERNAL_ERROR.
|
|
||||||
espeak_ERROR fifo_add_command(t_espeak_command *c);
|
|
||||||
|
|
||||||
// Add two espeak commands in a single transaction.
|
// Add two espeak commands in a single transaction.
|
||||||
//
|
//
|
||||||
// Note: this function fails if too many commands are already buffered.
|
// Note: this function fails if too many commands are already buffered.
|
||||||
// In such a case, the calling function could wait and then add again these commands.
|
// In such a case, the calling function could wait and then add again these commands.
|
||||||
//
|
espeak_ng_STATUS fifo_add_commands(t_espeak_command *c1, t_espeak_command *c2);
|
||||||
// Return: EE_OK: operation achieved
|
|
||||||
// EE_BUFFER_FULL: at least one command can not be buffered;
|
|
||||||
// you may try after a while to call the function again.
|
|
||||||
// EE_INTERNAL_ERROR.
|
|
||||||
espeak_ERROR fifo_add_commands(t_espeak_command *c1, t_espeak_command *c2);
|
|
||||||
|
|
||||||
// The current running command must be stopped and the awaiting commands are cleared.
|
// The current running command must be stopped and the awaiting commands are cleared.
|
||||||
// Return: EE_OK: operation achieved
|
espeak_ng_STATUS fifo_stop();
|
||||||
// EE_INTERNAL_ERROR.
|
|
||||||
espeak_ERROR fifo_stop();
|
|
||||||
|
|
||||||
// Is there a running command?
|
// Is there a running command?
|
||||||
// Returns 1 if yes; 0 otherwise.
|
// Returns 1 if yes; 0 otherwise.
|
||||||
|
|||||||
@@ -86,6 +86,17 @@ void WVoiceChanged(voice_t *wvoice)
|
|||||||
voice_samplerate = wvoice->samplerate;
|
voice_samplerate = wvoice->samplerate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static espeak_ERROR status_to_espeak_error(espeak_ng_STATUS status)
|
||||||
|
{
|
||||||
|
switch (status)
|
||||||
|
{
|
||||||
|
case ENS_OK: return EE_OK;
|
||||||
|
case ENOENT: return EE_NOT_FOUND;
|
||||||
|
case ENS_FIFO_BUFFER_FULL: return EE_BUFFER_FULL;
|
||||||
|
default: return EE_INTERNAL_ERROR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef USE_ASYNC
|
#ifdef USE_ASYNC
|
||||||
|
|
||||||
static int dispatch_audio(short *outbuf, int length, espeak_EVENT *event)
|
static int dispatch_audio(short *outbuf, int length, espeak_EVENT *event)
|
||||||
@@ -698,7 +709,7 @@ ESPEAK_API espeak_ERROR espeak_Synth(const void *text, size_t size,
|
|||||||
|
|
||||||
// Try to add these 2 commands (single transaction)
|
// Try to add these 2 commands (single transaction)
|
||||||
if (c1 && c2) {
|
if (c1 && c2) {
|
||||||
a_error = fifo_add_commands(c1, c2);
|
a_error = status_to_espeak_error(fifo_add_commands(c1, c2));
|
||||||
if (a_error != EE_OK) {
|
if (a_error != EE_OK) {
|
||||||
delete_espeak_command(c1);
|
delete_espeak_command(c1);
|
||||||
delete_espeak_command(c2);
|
delete_espeak_command(c2);
|
||||||
@@ -745,7 +756,7 @@ ESPEAK_API espeak_ERROR espeak_Synth_Mark(const void *text, size_t size,
|
|||||||
|
|
||||||
// Try to add these 2 commands (single transaction)
|
// Try to add these 2 commands (single transaction)
|
||||||
if (c1 && c2) {
|
if (c1 && c2) {
|
||||||
a_error = fifo_add_commands(c1, c2);
|
a_error = status_to_espeak_error(fifo_add_commands(c1, c2));
|
||||||
if (a_error != EE_OK) {
|
if (a_error != EE_OK) {
|
||||||
delete_espeak_command(c1);
|
delete_espeak_command(c1);
|
||||||
delete_espeak_command(c2);
|
delete_espeak_command(c2);
|
||||||
@@ -775,7 +786,7 @@ ESPEAK_API espeak_ERROR espeak_Key(const char *key)
|
|||||||
|
|
||||||
#ifdef USE_ASYNC
|
#ifdef USE_ASYNC
|
||||||
t_espeak_command *c = create_espeak_key(key, NULL);
|
t_espeak_command *c = create_espeak_key(key, NULL);
|
||||||
a_error = fifo_add_command(c);
|
a_error = status_to_espeak_error(fifo_add_command(c));
|
||||||
if (a_error != EE_OK)
|
if (a_error != EE_OK)
|
||||||
delete_espeak_command(c);
|
delete_espeak_command(c);
|
||||||
#endif
|
#endif
|
||||||
@@ -798,7 +809,7 @@ ESPEAK_API espeak_ERROR espeak_Char(wchar_t character)
|
|||||||
}
|
}
|
||||||
|
|
||||||
t_espeak_command *c = create_espeak_char(character, NULL);
|
t_espeak_command *c = create_espeak_char(character, NULL);
|
||||||
a_error = fifo_add_command(c);
|
a_error = status_to_espeak_error(fifo_add_command(c));
|
||||||
if (a_error != EE_OK)
|
if (a_error != EE_OK)
|
||||||
delete_espeak_command(c);
|
delete_espeak_command(c);
|
||||||
return a_error;
|
return a_error;
|
||||||
@@ -830,7 +841,7 @@ ESPEAK_API espeak_ERROR espeak_SetParameter(espeak_PARAMETER parameter, int valu
|
|||||||
|
|
||||||
t_espeak_command *c = create_espeak_parameter(parameter, value, relative);
|
t_espeak_command *c = create_espeak_parameter(parameter, value, relative);
|
||||||
|
|
||||||
a_error = fifo_add_command(c);
|
a_error = status_to_espeak_error(fifo_add_command(c));
|
||||||
if (a_error != EE_OK)
|
if (a_error != EE_OK)
|
||||||
delete_espeak_command(c);
|
delete_espeak_command(c);
|
||||||
return a_error;
|
return a_error;
|
||||||
@@ -853,7 +864,7 @@ ESPEAK_API espeak_ERROR espeak_SetPunctuationList(const wchar_t *punctlist)
|
|||||||
}
|
}
|
||||||
|
|
||||||
t_espeak_command *c = create_espeak_punctuation_list(punctlist);
|
t_espeak_command *c = create_espeak_punctuation_list(punctlist);
|
||||||
a_error = fifo_add_command(c);
|
a_error = status_to_espeak_error(fifo_add_command(c));
|
||||||
if (a_error != EE_OK)
|
if (a_error != EE_OK)
|
||||||
delete_espeak_command(c);
|
delete_espeak_command(c);
|
||||||
return a_error;
|
return a_error;
|
||||||
|
|||||||
Reference in New Issue
Block a user