Valdis Vitolins 8 years ago
parent
commit
f6a9e21f8b
7 changed files with 246 additions and 77 deletions
  1. 5
    5
      Makefile.am
  2. 16
    4
      src/libespeak-ng/speech.c
  3. 0
    1
      src/libespeak-ng/synthesize.h
  4. 0
    1
      src/libespeak-ng/wavegen.c
  5. 145
    0
      tests/api.c
  6. 80
    13
      tests/readclause.c
  7. 0
    53
      tests/voices.c

+ 5
- 5
Makefile.am View File

tests_readclause_test_LDADD = src/libespeak-ng-test.la tests_readclause_test_LDADD = src/libespeak-ng-test.la
tests_readclause_test_SOURCES = tests/readclause.c tests_readclause_test_SOURCES = tests/readclause.c


noinst_bin_PROGRAMS += tests/voices.test
noinst_bin_PROGRAMS += tests/api.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
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 %.check: %.test
@echo " TEST $<" @echo " TEST $<"
check: tests/encoding.check \ check: tests/encoding.check \
tests/tokenizer.check \ tests/tokenizer.check \
tests/readclause.check \ tests/readclause.check \
tests/voices.check \
tests/api.check \
tests/languages.check tests/languages.check


##### phoneme data: ##### phoneme data:

+ 16
- 4
src/libespeak-ng/speech.c View File

#include "event.h" #include "event.h"


unsigned char *outbuf = NULL; unsigned char *outbuf = NULL;
int outbuf_size = 0;


espeak_EVENT *event_list = NULL; espeak_EVENT *event_list = NULL;
int event_list_ix = 0; int event_list_ix = 0;
out_samplerate = 0; out_samplerate = 0;


#ifdef HAVE_PCAUDIOLIB_AUDIO_H #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 #endif


// buffer_length is in mS, allocate 2 bytes per sample // buffer_length is in mS, allocate 2 bytes per sample


count_samples = 0; count_samples = 0;


if (translator == NULL)
espeak_SetVoiceByName("default");
espeak_ng_STATUS status;
if (translator == NULL) {
status = espeak_SetVoiceByName("en");
if (status != ENS_OK)
return status;
}


if (p_decoder == NULL) if (p_decoder == NULL)
p_decoder = create_text_decoder(); p_decoder = create_text_decoder();


espeak_ng_STATUS status;
status = text_decoder_decode_string_multibyte(p_decoder, text, translator->encoding, flags); status = text_decoder_decode_string_multibyte(p_decoder, text, translator->encoding, flags);
if (status != ENS_OK) if (status != ENS_OK)
return status; return status;
#ifdef HAVE_PCAUDIOLIB_AUDIO_H #ifdef HAVE_PCAUDIOLIB_AUDIO_H
audio_object_close(my_audio); audio_object_close(my_audio);
audio_object_destroy(my_audio); audio_object_destroy(my_audio);
my_audio = NULL;
#endif #endif
out_samplerate = 0; out_samplerate = 0;
} }
outbuf = NULL; outbuf = NULL;
FreePhData(); FreePhData();
FreeVoiceList(); FreeVoiceList();
translator = NULL;

if (p_decoder != NULL) {
destroy_text_decoder(p_decoder);
p_decoder = NULL;
}


return ENS_OK; return ENS_OK;
} }

+ 0
- 1
src/libespeak-ng/synthesize.h View File

extern SPEED_FACTORS speed; extern SPEED_FACTORS speed;


extern long count_samples; extern long count_samples;
extern int outbuf_size;
extern unsigned char *out_ptr; extern unsigned char *out_ptr;
extern unsigned char *out_start; extern unsigned char *out_start;
extern unsigned char *out_end; extern unsigned char *out_end;

+ 0
- 1
src/libespeak-ng/wavegen.c View File

unsigned char *out_ptr; unsigned char *out_ptr;
unsigned char *out_start; unsigned char *out_start;
unsigned char *out_end; unsigned char *out_end;
int outbuf_size = 0;


// the queue of operations passed to wavegen from sythesize // the queue of operations passed to wavegen from sythesize
intptr_t wcmdq[N_WCMDQ][4]; intptr_t wcmdq[N_WCMDQ][4];

+ 145
- 0
tests/api.c View File

/*
* 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:
* <http://www.gnu.org/licenses/>.
*/

#include "config.h"

#include <assert.h>
#include <stdlib.h>
#include <string.h>

#include <espeak-ng/espeak_ng.h>
#include <espeak-ng/speak_lib.h>
#include <espeak-ng/encoding.h>

#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(translator == NULL);
assert(p_decoder == NULL);

assert(espeak_Terminate() == EE_OK);
assert(event_list == NULL);
assert(translator == NULL);
assert(p_decoder == NULL);
}

void
test_espeak_initialize()
{
printf("testing espeak_Initialize\n");

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
test_espeak_synth()
{
printf("testing espeak_Synth\n");

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);
}

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;
}

+ 80
- 13
tests/readclause.c View File

#include "synthesize.h" #include "synthesize.h"
#include "translate.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 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('a') == CLAUSE_NONE);
assert(clause_type_from_codepoint('.') == CLAUSE_PERIOD); assert(clause_type_from_codepoint('.') == CLAUSE_PERIOD);
void void
test_greek() 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(0x037E) == CLAUSE_QUESTION);
assert(clause_type_from_codepoint(0x0387) == CLAUSE_SEMICOLON); assert(clause_type_from_codepoint(0x0387) == CLAUSE_SEMICOLON);
void void
test_armenian() 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(0x055B) == (CLAUSE_EXCLAMATION | CLAUSE_PUNCTUATION_IN_WORD));
assert(clause_type_from_codepoint(0x055C) == (CLAUSE_EXCLAMATION | CLAUSE_PUNCTUATION_IN_WORD)); assert(clause_type_from_codepoint(0x055C) == (CLAUSE_EXCLAMATION | CLAUSE_PUNCTUATION_IN_WORD));
void void
test_arabic() 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(0x060C) == CLAUSE_COMMA);
assert(clause_type_from_codepoint(0x061B) == CLAUSE_SEMICOLON); assert(clause_type_from_codepoint(0x061B) == CLAUSE_SEMICOLON);
void void
test_devanagari() 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)); assert(clause_type_from_codepoint(0x0964) == (CLAUSE_PERIOD | CLAUSE_OPTIONAL_SPACE_AFTER));
} }
void void
test_tibetan() 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(0x0F0D) == (CLAUSE_PERIOD | CLAUSE_OPTIONAL_SPACE_AFTER));
assert(clause_type_from_codepoint(0x0F0E) == CLAUSE_PARAGRAPH); assert(clause_type_from_codepoint(0x0F0E) == CLAUSE_PARAGRAPH);
void void
test_sinhala() 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)); assert(clause_type_from_codepoint(0x0DF4) == (CLAUSE_PERIOD | CLAUSE_OPTIONAL_SPACE_AFTER));
} }
void void
test_georgian() test_georgian()
{ {
printf("testing Georgian (Geor) script classification\n");
printf("testing Georgian (Geor)\n");


assert(clause_type_from_codepoint(0x10FB) == CLAUSE_PARAGRAPH); assert(clause_type_from_codepoint(0x10FB) == CLAUSE_PARAGRAPH);
} }
void void
test_ethiopic() 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(0x1362) == CLAUSE_PERIOD);
assert(clause_type_from_codepoint(0x1363) == CLAUSE_COMMA); assert(clause_type_from_codepoint(0x1363) == CLAUSE_COMMA);
void void
test_ideographic() 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(0x3001) == (CLAUSE_COMMA | CLAUSE_OPTIONAL_SPACE_AFTER));
assert(clause_type_from_codepoint(0x3002) == (CLAUSE_PERIOD | CLAUSE_OPTIONAL_SPACE_AFTER)); assert(clause_type_from_codepoint(0x3002) == (CLAUSE_PERIOD | CLAUSE_OPTIONAL_SPACE_AFTER));
void void
test_fullwidth() 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(0xFF01) == (CLAUSE_EXCLAMATION | CLAUSE_OPTIONAL_SPACE_AFTER));
assert(clause_type_from_codepoint(0xFF0C) == (CLAUSE_COMMA | CLAUSE_OPTIONAL_SPACE_AFTER)); assert(clause_type_from_codepoint(0xFF0C) == (CLAUSE_COMMA | CLAUSE_OPTIONAL_SPACE_AFTER));
assert(clause_type_from_codepoint(0xFF1F) == (CLAUSE_QUESTION | CLAUSE_OPTIONAL_SPACE_AFTER)); assert(clause_type_from_codepoint(0xFF1F) == (CLAUSE_QUESTION | CLAUSE_OPTIONAL_SPACE_AFTER));
} }


void
test_uts51_emoji_character()
{
printf("testing Emoji ... UTS-51 ED-3. emoji character\n");

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);
}

int int
main(int argc, char **argv) main(int argc, char **argv)
{ {
test_latin_common();
assert(espeak_Initialize(AUDIO_OUTPUT_SYNCHRONOUS, 0, NULL, espeakINITIALIZE_DONT_EXIT) == 22050);

test_latin();
test_greek(); test_greek();
test_armenian(); test_armenian();
test_arabic(); test_arabic();
test_ideographic(); test_ideographic();
test_fullwidth(); test_fullwidth();


test_uts51_emoji_character();

assert(espeak_Terminate() == EE_OK);

return EXIT_SUCCESS; return EXIT_SUCCESS;
} }

// References:
// [UTS-51] Unicode Emoji (http://www.unicode.org/reports/tr51/tr51-12.html) 5.0-12. 2017-05-18

+ 0
- 53
tests/voices.c View File

/*
* 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:
* <http://www.gnu.org/licenses/>.
*/

#include "config.h"

#include <assert.h>
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>

#include <espeak-ng/espeak_ng.h>
#include <espeak-ng/speak_lib.h>

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;
}

Loading…
Cancel
Save