From 37bae427c4d08b9e0a1099b60cceeaaef905936b Mon Sep 17 00:00:00 2001 From: "Reece H. Dunn" Date: Fri, 19 May 2017 20:11:10 +0100 Subject: [PATCH 01/10] Remove the current voice tests. These tests are limited in scope and should really be part of a more comprehensive API tests. --- Makefile.am | 7 ------- tests/voices.c | 53 -------------------------------------------------- 2 files changed, 60 deletions(-) delete mode 100644 tests/voices.c diff --git a/Makefile.am b/Makefile.am index 61b33a52..900a9049 100644 --- a/Makefile.am +++ b/Makefile.am @@ -245,12 +245,6 @@ tests_readclause_test_CFLAGS = -Isrc/libespeak-ng ${AM_CFLAGS} tests_readclause_test_LDADD = src/libespeak-ng-test.la tests_readclause_test_SOURCES = tests/readclause.c -noinst_bin_PROGRAMS += tests/voices.test - -tests_voices_test_LDADD = src/libespeak-ng-test.la -tests_voices_test_CFLAGS = -Isrc/libespeak-ng ${AM_CFLAGS} -tests_voices_test_SOURCES = tests/voices.c - %.check: %.test @echo " TEST $<" @ESPEAK_DATA_PATH=$(PWD) $< && echo " PASSED $<" @@ -258,7 +252,6 @@ tests_voices_test_SOURCES = tests/voices.c check: tests/encoding.check \ tests/tokenizer.check \ tests/readclause.check \ - tests/voices.check \ tests/languages.check ##### phoneme data: diff --git a/tests/voices.c b/tests/voices.c deleted file mode 100644 index d5775a74..00000000 --- a/tests/voices.c +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (C) 2017 Reece H. Dunn - * - * 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 - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program 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 program; if not, write see: - * . - */ - -#include "config.h" - -#include -#include -#include -#include - -#include -#include - -void -test_selection_by_name() -{ - printf("testing selection of voice by name\n"); - - assert(espeak_SetVoiceByName("de") == EE_OK); - - assert(espeak_SetVoiceByName("und") == EE_NOT_FOUND); - - assert(espeak_ng_SetVoiceByName("de") == ENS_OK); - - assert(espeak_ng_SetVoiceByName("und") == ENS_VOICE_NOT_FOUND); -} - -int -main(int argc, char **argv) -{ - assert(espeak_Initialize(AUDIO_OUTPUT_SYNCHRONOUS, 0, NULL, espeakINITIALIZE_DONT_EXIT) == 22050); - - test_selection_by_name(); - - assert(espeak_Terminate() == EE_OK); - - return EXIT_SUCCESS; -} From 5aa47e01ea0f97705bc562607ab70450a1514c4e Mon Sep 17 00:00:00 2001 From: "Reece H. Dunn" Date: Fri, 19 May 2017 20:40:15 +0100 Subject: [PATCH 02/10] Simplify the readclause test names. This is to support additional logic (i.e. testing the ReadClause function) in the test functions. --- tests/readclause.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/tests/readclause.c b/tests/readclause.c index ce3ba148..26c6abca 100644 --- a/tests/readclause.c +++ b/tests/readclause.c @@ -35,9 +35,9 @@ #include "translate.h" void -test_latin_common() +test_latin() { - printf("testing Latin/Common (Latn/Zyyy) script classification\n"); + printf("testing Latin (Latn)\n"); assert(clause_type_from_codepoint('a') == CLAUSE_NONE); assert(clause_type_from_codepoint('.') == CLAUSE_PERIOD); @@ -58,7 +58,7 @@ test_latin_common() void test_greek() { - printf("testing Greek (Grek) script classification\n"); + printf("testing Greek (Grek)\n"); assert(clause_type_from_codepoint(0x037E) == CLAUSE_QUESTION); assert(clause_type_from_codepoint(0x0387) == CLAUSE_SEMICOLON); @@ -67,7 +67,7 @@ test_greek() void test_armenian() { - printf("testing Armenian (Armn) script classification\n"); + printf("testing Armenian (Armn)\n"); assert(clause_type_from_codepoint(0x055B) == (CLAUSE_EXCLAMATION | CLAUSE_PUNCTUATION_IN_WORD)); assert(clause_type_from_codepoint(0x055C) == (CLAUSE_EXCLAMATION | CLAUSE_PUNCTUATION_IN_WORD)); @@ -79,7 +79,7 @@ test_armenian() void test_arabic() { - printf("testing Arabic (Arab) script classification\n"); + printf("testing Arabic (Arab)\n"); assert(clause_type_from_codepoint(0x060C) == CLAUSE_COMMA); assert(clause_type_from_codepoint(0x061B) == CLAUSE_SEMICOLON); @@ -90,7 +90,7 @@ test_arabic() void test_devanagari() { - printf("testing Devanagari (Deva) script classification\n"); + printf("testing Devanagari (Deva)\n"); assert(clause_type_from_codepoint(0x0964) == (CLAUSE_PERIOD | CLAUSE_OPTIONAL_SPACE_AFTER)); } @@ -98,7 +98,7 @@ test_devanagari() void test_tibetan() { - printf("testing Tibetan (Tibt) script classification\n"); + printf("testing Tibetan (Tibt)\n"); assert(clause_type_from_codepoint(0x0F0D) == (CLAUSE_PERIOD | CLAUSE_OPTIONAL_SPACE_AFTER)); assert(clause_type_from_codepoint(0x0F0E) == CLAUSE_PARAGRAPH); @@ -107,7 +107,7 @@ test_tibetan() void test_sinhala() { - printf("testing Sinhala (Sinh) script classification\n"); + printf("testing Sinhala (Sinh)\n"); assert(clause_type_from_codepoint(0x0DF4) == (CLAUSE_PERIOD | CLAUSE_OPTIONAL_SPACE_AFTER)); } @@ -115,7 +115,7 @@ test_sinhala() void test_georgian() { - printf("testing Georgian (Geor) script classification\n"); + printf("testing Georgian (Geor)\n"); assert(clause_type_from_codepoint(0x10FB) == CLAUSE_PARAGRAPH); } @@ -123,7 +123,7 @@ test_georgian() void test_ethiopic() { - printf("testing Ethiopic (Ethi) script classification\n"); + printf("testing Ethiopic (Ethi)\n"); assert(clause_type_from_codepoint(0x1362) == CLAUSE_PERIOD); assert(clause_type_from_codepoint(0x1363) == CLAUSE_COMMA); @@ -137,7 +137,7 @@ test_ethiopic() void test_ideographic() { - printf("testing Ideographic (Hani) script classification\n"); + printf("testing Ideographic (Hani)\n"); assert(clause_type_from_codepoint(0x3001) == (CLAUSE_COMMA | CLAUSE_OPTIONAL_SPACE_AFTER)); assert(clause_type_from_codepoint(0x3002) == (CLAUSE_PERIOD | CLAUSE_OPTIONAL_SPACE_AFTER)); @@ -146,7 +146,7 @@ test_ideographic() void test_fullwidth() { - printf("testing Full Width/Common (Zyyy) script classification\n"); + printf("testing Full Width\n"); assert(clause_type_from_codepoint(0xFF01) == (CLAUSE_EXCLAMATION | CLAUSE_OPTIONAL_SPACE_AFTER)); assert(clause_type_from_codepoint(0xFF0C) == (CLAUSE_COMMA | CLAUSE_OPTIONAL_SPACE_AFTER)); @@ -159,7 +159,7 @@ test_fullwidth() int main(int argc, char **argv) { - test_latin_common(); + test_latin(); test_greek(); test_armenian(); test_arabic(); From 27a08c5fea43226378ddd0f6c25dfa57356efdca Mon Sep 17 00:00:00 2001 From: "Reece H. Dunn" Date: Sat, 20 May 2017 09:50:28 +0100 Subject: [PATCH 03/10] Test ReadClause on single character emoji sequences. --- tests/readclause.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/tests/readclause.c b/tests/readclause.c index 26c6abca..0edf540a 100644 --- a/tests/readclause.c +++ b/tests/readclause.c @@ -34,6 +34,28 @@ #include "synthesize.h" #include "translate.h" +// Arguments to ReadClause. Declared here to avoid duplicating them across the +// different test functions. +static char source[N_TR_SOURCE+40]; // extra space for embedded command & voice change info at end +static short charix[N_TR_SOURCE+4]; +static int charix_top = 0; +static int tone2; +static char voice_change_name[40]; +static int terminator; + +static espeak_ng_STATUS +set_text(const char *text, const char *voicename) +{ + espeak_ng_STATUS status = espeak_ng_SetVoiceByName(voicename); + if (status != ENS_OK) + return status; + + if (p_decoder == NULL) + p_decoder = create_text_decoder(); + + return text_decoder_decode_string(p_decoder, text, -1, ESPEAKNG_ENCODING_UTF_8); +} + void test_latin() { @@ -156,9 +178,53 @@ test_fullwidth() assert(clause_type_from_codepoint(0xFF1F) == (CLAUSE_QUESTION | CLAUSE_OPTIONAL_SPACE_AFTER)); } +void +test_emoji_single_character_sequences() +{ + short retix[] = { + 0, -1, -1, + 2, -1, -1, + 3, -1, -1, + 4, -1, -1, -1, + 5, -1, -1, -1, + 6, + 0 }; + + assert(set_text( + "\xE2\x86\x94" // [2194] left right arrow + "\xE2\x86\x95" // [2195] up down arrow + "\xE2\x9B\x94" // [26D5] no entry + "\xF0\x9F\x90\x8B" // [1F40B] whale + "\xF0\x9F\x90\xAC", // [1F42C] dolphin + "en") == ENS_OK); + + assert(ReadClause(translator, source, charix, &charix_top, N_TR_SOURCE, &tone2, voice_change_name) == CLAUSE_EOF); + assert(!strcmp(source, + "\xE2\x86\x94" // [2194] left right arrow + "\xE2\x86\x95" // [2195] up down arrow + "\xE2\x9B\x94" // [26D5] no entry + "\xF0\x9F\x90\x8B" // [1F40B] whale + "\xF0\x9F\x90\xAC" // [1F42C] dolphin + " ")); + assert(charix_top == (sizeof(retix)/sizeof(retix[0])) - 2); + assert(!memcmp(charix, retix, sizeof(retix))); + assert(tone2 == 0); + assert(voice_change_name[0] == 0); +} + +void +test_emoji() +{ + printf("testing Emoji\n"); + + test_emoji_single_character_sequences(); +} + int main(int argc, char **argv) { + assert(espeak_Initialize(AUDIO_OUTPUT_SYNCHRONOUS, 0, NULL, espeakINITIALIZE_DONT_EXIT) == 22050); + test_latin(); test_greek(); test_armenian(); @@ -171,5 +237,9 @@ main(int argc, char **argv) test_ideographic(); test_fullwidth(); + test_emoji(); + + assert(espeak_Terminate() == EE_OK); + return EXIT_SUCCESS; } From 3189d194f1b522d4682fb8a39b853be5bd6a1ae1 Mon Sep 17 00:00:00 2001 From: "Reece H. Dunn" Date: Sat, 20 May 2017 15:33:56 +0100 Subject: [PATCH 04/10] Testing UTS 51 (5.0-12) ED-3. emoji character --- tests/readclause.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/tests/readclause.c b/tests/readclause.c index 0edf540a..90dbd72f 100644 --- a/tests/readclause.c +++ b/tests/readclause.c @@ -179,8 +179,10 @@ test_fullwidth() } void -test_emoji_single_character_sequences() +test_uts51_emoji_character() { + printf("testing Emoji ... UTS-51 ED-3. emoji character\n"); + short retix[] = { 0, -1, -1, 2, -1, -1, @@ -212,14 +214,6 @@ test_emoji_single_character_sequences() assert(voice_change_name[0] == 0); } -void -test_emoji() -{ - printf("testing Emoji\n"); - - test_emoji_single_character_sequences(); -} - int main(int argc, char **argv) { @@ -237,9 +231,12 @@ main(int argc, char **argv) test_ideographic(); test_fullwidth(); - test_emoji(); + test_uts51_emoji_character(); assert(espeak_Terminate() == EE_OK); return EXIT_SUCCESS; } + +// References: +// [UTS-51] Unicode Emoji (http://www.unicode.org/reports/tr51/tr51-12.html) 5.0-12. 2017-05-18 From 9fc2efb1fafd2704523bbd33aec86e6e2fdef1a6 Mon Sep 17 00:00:00 2001 From: "Reece H. Dunn" Date: Sun, 21 May 2017 09:49:35 +0100 Subject: [PATCH 05/10] Don't re-initialize my_audio if espeak_ng_InitializeOutput is called multiple times. --- src/libespeak-ng/speech.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/libespeak-ng/speech.c b/src/libespeak-ng/speech.c index 368520db..1815375f 100644 --- a/src/libespeak-ng/speech.c +++ b/src/libespeak-ng/speech.c @@ -252,7 +252,8 @@ ESPEAK_NG_API espeak_ng_STATUS espeak_ng_InitializeOutput(espeak_ng_OUTPUT_MODE out_samplerate = 0; #ifdef HAVE_PCAUDIOLIB_AUDIO_H - my_audio = create_audio_device_object(device, "eSpeak", "Text-to-Speech"); + if (my_audio == NULL) + my_audio = create_audio_device_object(device, "eSpeak", "Text-to-Speech"); #endif // buffer_length is in mS, allocate 2 bytes per sample @@ -886,6 +887,7 @@ ESPEAK_NG_API espeak_ng_STATUS espeak_ng_Terminate(void) #ifdef HAVE_PCAUDIOLIB_AUDIO_H audio_object_close(my_audio); audio_object_destroy(my_audio); + my_audio = NULL; #endif out_samplerate = 0; } From 6ab131484337ad3b17445b7db0e63817bb7b8b6f Mon Sep 17 00:00:00 2001 From: "Reece H. Dunn" Date: Sun, 21 May 2017 10:02:27 +0100 Subject: [PATCH 06/10] Move outbuf_size to where it is actually used. --- src/libespeak-ng/speech.c | 1 + src/libespeak-ng/synthesize.h | 1 - src/libespeak-ng/wavegen.c | 1 - 3 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/libespeak-ng/speech.c b/src/libespeak-ng/speech.c index 1815375f..9ac8f0c3 100644 --- a/src/libespeak-ng/speech.c +++ b/src/libespeak-ng/speech.c @@ -58,6 +58,7 @@ #include "event.h" unsigned char *outbuf = NULL; +int outbuf_size = 0; espeak_EVENT *event_list = NULL; int event_list_ix = 0; diff --git a/src/libespeak-ng/synthesize.h b/src/libespeak-ng/synthesize.h index a83784c4..a2c52ea0 100644 --- a/src/libespeak-ng/synthesize.h +++ b/src/libespeak-ng/synthesize.h @@ -512,7 +512,6 @@ extern int formant_rate[]; // max rate of change of each formant extern SPEED_FACTORS speed; extern long count_samples; -extern int outbuf_size; extern unsigned char *out_ptr; extern unsigned char *out_start; extern unsigned char *out_end; diff --git a/src/libespeak-ng/wavegen.c b/src/libespeak-ng/wavegen.c index ee355625..dd656f9c 100644 --- a/src/libespeak-ng/wavegen.c +++ b/src/libespeak-ng/wavegen.c @@ -107,7 +107,6 @@ static double two_pi_t; unsigned char *out_ptr; unsigned char *out_start; unsigned char *out_end; -int outbuf_size = 0; // the queue of operations passed to wavegen from sythesize intptr_t wcmdq[N_WCMDQ][4]; From ae6116bf97edd1d3879ecb9a3b00b1c1993b11e7 Mon Sep 17 00:00:00 2001 From: "Reece H. Dunn" Date: Sun, 21 May 2017 10:47:47 +0100 Subject: [PATCH 07/10] Fix calling espeak_Synth without first setting a voice, with tests. --- Makefile.am | 7 ++++ src/libespeak-ng/speech.c | 2 +- tests/api.c | 86 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 94 insertions(+), 1 deletion(-) create mode 100644 tests/api.c diff --git a/Makefile.am b/Makefile.am index 900a9049..52df9575 100644 --- a/Makefile.am +++ b/Makefile.am @@ -245,6 +245,12 @@ tests_readclause_test_CFLAGS = -Isrc/libespeak-ng ${AM_CFLAGS} tests_readclause_test_LDADD = src/libespeak-ng-test.la tests_readclause_test_SOURCES = tests/readclause.c +noinst_bin_PROGRAMS += tests/api.test + +tests_api_test_CFLAGS = -Isrc/libespeak-ng ${AM_CFLAGS} +tests_api_test_LDADD = src/libespeak-ng-test.la +tests_api_test_SOURCES = tests/api.c + %.check: %.test @echo " TEST $<" @ESPEAK_DATA_PATH=$(PWD) $< && echo " PASSED $<" @@ -252,6 +258,7 @@ tests_readclause_test_SOURCES = tests/readclause.c check: tests/encoding.check \ tests/tokenizer.check \ tests/readclause.check \ + tests/api.check \ tests/languages.check ##### phoneme data: diff --git a/src/libespeak-ng/speech.c b/src/libespeak-ng/speech.c index 9ac8f0c3..6e2c3b04 100644 --- a/src/libespeak-ng/speech.c +++ b/src/libespeak-ng/speech.c @@ -399,7 +399,7 @@ static espeak_ng_STATUS Synthesize(unsigned int unique_identifier, const void *t count_samples = 0; if (translator == NULL) - espeak_SetVoiceByName("default"); + espeak_SetVoiceByName("en"); if (p_decoder == NULL) p_decoder = create_text_decoder(); diff --git a/tests/api.c b/tests/api.c new file mode 100644 index 00000000..859e78e4 --- /dev/null +++ b/tests/api.c @@ -0,0 +1,86 @@ +/* + * Copyright (C) 2017 Reece H. Dunn + * + * 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 program; if not, write see: + * . + */ + +#include "config.h" + +#include +#include +#include + +#include +#include +#include + +#include "speech.h" +#include "phoneme.h" +#include "synthesize.h" +#include "translate.h" + +void +test_espeak_terminate_without_initialize() +{ + printf("testing espeak_Terminate without espeak_Initialize\n"); + + assert(event_list == NULL); + + assert(espeak_Terminate() == EE_OK); + assert(event_list == NULL); +} + +void +test_espeak_initialize() +{ + printf("testing espeak_Initialize\n"); + + assert(event_list == NULL); + + assert(espeak_Initialize(AUDIO_OUTPUT_PLAYBACK, 0, NULL, 0) == 22050); + assert(event_list != NULL); + + assert(espeak_Terminate() == EE_OK); + assert(event_list == NULL); +} + +void +test_espeak_synth() +{ + printf("testing espeak_Synth\n"); + + assert(event_list == NULL); + + assert(espeak_Initialize(AUDIO_OUTPUT_RETRIEVAL, 0, NULL, 0) == 22050); + assert(event_list != NULL); + + const char *test = "One two three."; + assert(espeak_Synth(test, strlen(test)+1, 0, POS_CHARACTER, 0, espeakCHARS_AUTO, NULL, NULL) == EE_OK); + assert(espeak_Synchronize() == EE_OK); + + assert(espeak_Terminate() == EE_OK); + assert(event_list == NULL); +} + +int +main(int argc, char **argv) +{ + test_espeak_terminate_without_initialize(); + test_espeak_initialize(); + + test_espeak_synth(); + + return EXIT_SUCCESS; +} From 63e2826753ba2a2c199b56f8278b3848246b6b92 Mon Sep 17 00:00:00 2001 From: "Reece H. Dunn" Date: Sun, 21 May 2017 12:01:46 +0100 Subject: [PATCH 08/10] Ensure that the old translator is not used after calling espeak_Terminate. --- src/libespeak-ng/speech.c | 1 + tests/api.c | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/src/libespeak-ng/speech.c b/src/libespeak-ng/speech.c index 6e2c3b04..322389f6 100644 --- a/src/libespeak-ng/speech.c +++ b/src/libespeak-ng/speech.c @@ -899,6 +899,7 @@ ESPEAK_NG_API espeak_ng_STATUS espeak_ng_Terminate(void) outbuf = NULL; FreePhData(); FreeVoiceList(); + translator = NULL; return ENS_OK; } diff --git a/tests/api.c b/tests/api.c index 859e78e4..4ae0eeaf 100644 --- a/tests/api.c +++ b/tests/api.c @@ -37,9 +37,11 @@ test_espeak_terminate_without_initialize() printf("testing espeak_Terminate without espeak_Initialize\n"); assert(event_list == NULL); + assert(translator == NULL); assert(espeak_Terminate() == EE_OK); assert(event_list == NULL); + assert(translator == NULL); } void @@ -48,12 +50,15 @@ test_espeak_initialize() printf("testing espeak_Initialize\n"); assert(event_list == NULL); + assert(translator == NULL); assert(espeak_Initialize(AUDIO_OUTPUT_PLAYBACK, 0, NULL, 0) == 22050); assert(event_list != NULL); + assert(translator == NULL); assert(espeak_Terminate() == EE_OK); assert(event_list == NULL); + assert(translator == NULL); } void @@ -62,16 +67,22 @@ test_espeak_synth() printf("testing espeak_Synth\n"); assert(event_list == NULL); + assert(translator == NULL); assert(espeak_Initialize(AUDIO_OUTPUT_RETRIEVAL, 0, NULL, 0) == 22050); assert(event_list != NULL); + assert(translator == NULL); const char *test = "One two three."; assert(espeak_Synth(test, strlen(test)+1, 0, POS_CHARACTER, 0, espeakCHARS_AUTO, NULL, NULL) == EE_OK); + assert(translator != NULL); + assert(espeak_Synchronize() == EE_OK); + assert(translator != NULL); assert(espeak_Terminate() == EE_OK); assert(event_list == NULL); + assert(translator == NULL); } int @@ -81,6 +92,7 @@ main(int argc, char **argv) test_espeak_initialize(); test_espeak_synth(); + test_espeak_synth(); // Check that this does not crash when run a second time. return EXIT_SUCCESS; } From dced9f58fd1bdddf76b3d5b9b30fc7b51f7f5cd9 Mon Sep 17 00:00:00 2001 From: "Reece H. Dunn" Date: Sun, 21 May 2017 12:07:15 +0100 Subject: [PATCH 09/10] Clean up the decoder memory in espeak_Terminate. --- src/libespeak-ng/speech.c | 5 +++++ tests/api.c | 10 ++++++++++ 2 files changed, 15 insertions(+) diff --git a/src/libespeak-ng/speech.c b/src/libespeak-ng/speech.c index 322389f6..3427e51c 100644 --- a/src/libespeak-ng/speech.c +++ b/src/libespeak-ng/speech.c @@ -901,6 +901,11 @@ ESPEAK_NG_API espeak_ng_STATUS espeak_ng_Terminate(void) FreeVoiceList(); translator = NULL; + if (p_decoder != NULL) { + destroy_text_decoder(p_decoder); + p_decoder = NULL; + } + return ENS_OK; } diff --git a/tests/api.c b/tests/api.c index 4ae0eeaf..84362206 100644 --- a/tests/api.c +++ b/tests/api.c @@ -38,10 +38,12 @@ test_espeak_terminate_without_initialize() assert(event_list == NULL); assert(translator == NULL); + assert(p_decoder == NULL); assert(espeak_Terminate() == EE_OK); assert(event_list == NULL); assert(translator == NULL); + assert(p_decoder == NULL); } void @@ -51,14 +53,17 @@ test_espeak_initialize() assert(event_list == NULL); assert(translator == NULL); + assert(p_decoder == NULL); assert(espeak_Initialize(AUDIO_OUTPUT_PLAYBACK, 0, NULL, 0) == 22050); assert(event_list != NULL); assert(translator == NULL); + assert(p_decoder == NULL); assert(espeak_Terminate() == EE_OK); assert(event_list == NULL); assert(translator == NULL); + assert(p_decoder == NULL); } void @@ -68,21 +73,26 @@ test_espeak_synth() assert(event_list == NULL); assert(translator == NULL); + assert(p_decoder == NULL); assert(espeak_Initialize(AUDIO_OUTPUT_RETRIEVAL, 0, NULL, 0) == 22050); assert(event_list != NULL); assert(translator == NULL); + assert(p_decoder == NULL); const char *test = "One two three."; assert(espeak_Synth(test, strlen(test)+1, 0, POS_CHARACTER, 0, espeakCHARS_AUTO, NULL, NULL) == EE_OK); assert(translator != NULL); + assert(p_decoder != NULL); assert(espeak_Synchronize() == EE_OK); assert(translator != NULL); + assert(p_decoder != NULL); assert(espeak_Terminate() == EE_OK); assert(event_list == NULL); assert(translator == NULL); + assert(p_decoder == NULL); } int From fbd2e679fc1afa3c6325358ff986eb8c156ee3e9 Mon Sep 17 00:00:00 2001 From: "Reece H. Dunn" Date: Sun, 21 May 2017 12:44:10 +0100 Subject: [PATCH 10/10] Don't crash if loading the default voice fails. --- src/libespeak-ng/speech.c | 9 ++++++--- tests/api.c | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/src/libespeak-ng/speech.c b/src/libespeak-ng/speech.c index 3427e51c..bd8cd294 100644 --- a/src/libespeak-ng/speech.c +++ b/src/libespeak-ng/speech.c @@ -398,13 +398,16 @@ static espeak_ng_STATUS Synthesize(unsigned int unique_identifier, const void *t count_samples = 0; - if (translator == NULL) - espeak_SetVoiceByName("en"); + espeak_ng_STATUS status; + if (translator == NULL) { + status = espeak_SetVoiceByName("en"); + if (status != ENS_OK) + return status; + } if (p_decoder == NULL) p_decoder = create_text_decoder(); - espeak_ng_STATUS status; status = text_decoder_decode_string_multibyte(p_decoder, text, translator->encoding, flags); if (status != ENS_OK) return status; diff --git a/tests/api.c b/tests/api.c index 84362206..b7cdacce 100644 --- a/tests/api.c +++ b/tests/api.c @@ -95,14 +95,51 @@ test_espeak_synth() assert(p_decoder == NULL); } +void +test_espeak_synth_no_voices(const char *path) +{ + printf("testing espeak_Synth in path with no voices\n"); + + assert(event_list == NULL); + assert(translator == NULL); + assert(p_decoder == NULL); + + assert(espeak_Initialize(AUDIO_OUTPUT_RETRIEVAL, 0, path, espeakINITIALIZE_DONT_EXIT) == 22050); + assert(event_list != NULL); + assert(translator == NULL); + assert(p_decoder == NULL); + + const char *test = "One two three."; + assert(espeak_Synth(test, strlen(test)+1, 0, POS_CHARACTER, 0, espeakCHARS_AUTO, NULL, NULL) == EE_INTERNAL_ERROR); + assert(translator == NULL); + assert(p_decoder == NULL); + + assert(espeak_Synchronize() == EE_OK); + assert(translator == NULL); + assert(p_decoder == NULL); + + assert(espeak_Terminate() == EE_OK); + assert(event_list == NULL); + assert(translator == NULL); + assert(p_decoder == NULL); +} + int main(int argc, char **argv) { + char *progdir = strdup(argv[0]); + char *dir = strrchr(progdir, '/'); + if (dir != NULL) *dir = 0; + test_espeak_terminate_without_initialize(); test_espeak_initialize(); test_espeak_synth(); test_espeak_synth(); // Check that this does not crash when run a second time. + test_espeak_synth_no_voices(progdir); + test_espeak_synth(); + + free(progdir); return EXIT_SUCCESS; }