Skip to content

Commit

Permalink
Create an espeak_ng_EncodingFromName API.
Browse files Browse the repository at this point in the history
  • Loading branch information
rhdunn committed Mar 27, 2017
1 parent e12abb4 commit b47363b
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ src/espeak-ng
src/espeakedit
src/speak-ng

tests/*.test

espeak-ng.pc

espeak-ng-*.tar.gz
Expand Down
16 changes: 15 additions & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ bin_PROGRAMS =
lib_LTLIBRARIES =
man1_MANS =

noinst_bin_PROGRAMS =
noinst_bindir =

##### ChangeLog:

ChangeLog:
Expand Down Expand Up @@ -109,7 +112,8 @@ docs: docs/index.html \
src/speak-ng.1.html \
README.html

check: apk-check
check: tests/encoding.test
tests/encoding.test

##### build targets:

Expand Down Expand Up @@ -142,6 +146,7 @@ src_libespeak_ng_la_SOURCES = \
src/libespeak-ng/compiledict.c \
src/libespeak-ng/compilembrola.c \
src/libespeak-ng/dictionary.c \
src/libespeak-ng/encoding.c \
src/libespeak-ng/error.c \
src/libespeak-ng/espeak_api.c \
src/libespeak-ng/ieee80.c \
Expand Down Expand Up @@ -200,6 +205,15 @@ src_espeak_ng_LDADD = src/libespeak-ng.la ${PCAUDIOLIB_LIBS}
src_espeak_ng_CFLAGS = -Isrc/include ${AM_CFLAGS}
src_espeak_ng_SOURCES = src/espeak-ng.c

##### tests:

noinst_bin_PROGRAMS += tests/encoding.test

tests_encoding_test_CFLAGS = -Isrc/libespeak-ng -Isrc/include -D _POSIX_C_SOURCE=200112L ${AM_CFLAGS}
tests_encoding_test_SOURCES = \
src/libespeak-ng/encoding.c \
tests/encoding.c

##### phoneme data:

espeak-ng-data/phondata: phsource/phonemes.stamp
Expand Down
10 changes: 10 additions & 0 deletions src/include/espeak-ng/espeak_ng.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,16 @@ espeak_ng_CompilePhonemeDataPath(long rate,
FILE *log,
espeak_ng_ERROR_CONTEXT *context);

/* eSpeak NG 1.49.2 */

typedef enum
{
ESPEAKNG_ENCODING_UNKNOWN,
} espeak_ng_ENCODING;

ESPEAK_NG_API espeak_ng_ENCODING
espeak_ng_EncodingFromName(const char *encoding);

#ifdef __cplusplus
}
#endif
Expand Down
50 changes: 50 additions & 0 deletions src/libespeak-ng/encoding.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* 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, see: <http://www.gnu.org/licenses/>.
*/

#include "config.h"

#include <string.h>

#include <espeak-ng/espeak_ng.h>

#include "speech.h"

static int
LookupMnemValue(MNEM_TAB *table,
const char *string)
{
while (table->mnem != NULL) {
if (strcmp(string, table->mnem) == 0)
return table->value;
table++;
}
return table->value;
}

MNEM_TAB mnem_encoding[] = {
{ NULL, ESPEAKNG_ENCODING_UNKNOWN }
};

#pragma GCC visibility push(default)

espeak_ng_ENCODING
espeak_ng_EncodingFromName(const char *encoding)
{
return LookupMnemValue(mnem_encoding, encoding);
}

#pragma GCC visibility pop
43 changes: 43 additions & 0 deletions tests/encoding.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* 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 <stdio.h>

#include <espeak-ng/espeak_ng.h>

void
test_unknown_encoding()
{
printf("testing unknown encoding\n");

assert(espeak_ng_EncodingFromName("") == ESPEAKNG_ENCODING_UNKNOWN);
assert(espeak_ng_EncodingFromName("abcxyz") == ESPEAKNG_ENCODING_UNKNOWN);
}

int
main(int argc, char **argv)
{
test_unknown_encoding();
printf("done\n");

return EXIT_SUCCESS;
}

0 comments on commit b47363b

Please sign in to comment.