123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
-
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <emscripten.h>
- #include "speak_lib.h"
-
- static int gSamplerate = 0;
-
- class eSpeakNGWorker {
- public:
- eSpeakNGWorker() : rate(espeakRATE_NORMAL), pitch(50), current_voice(NULL) {
- if (!gSamplerate) {
- gSamplerate = espeak_Initialize(
- AUDIO_OUTPUT_SYNCHRONOUS, 100, NULL, espeakINITIALIZE_DONT_EXIT);
- }
- samplerate = gSamplerate;
- voices = espeak_ListVoices(NULL);
- }
-
- void synth_(const char* aText, void* aCallback) {
- t_espeak_callback* cb = reinterpret_cast<t_espeak_callback*>(aCallback);
- espeak_SetSynthCallback(cb);
- espeak_SetParameter(espeakPITCH, pitch, 0);
- espeak_SetParameter(espeakRATE, rate, 0);
-
- if (current_voice)
- espeak_SetVoiceByProperties(current_voice);
- else
- espeak_SetVoiceByName("default");
-
- espeak_Synth(aText, 0, 0, POS_CHARACTER, 0, 0, NULL, NULL);
-
-
- espeak_SetSynthCallback(NULL);
- }
-
- int synth_ipa_(const char* aText, const char* virtualFileName) {
-
-
-
-
- espeak_SetSynthCallback(NULL);
-
- int phoneme_options = (1 << 1);
- int use_custom_phoneme_separator = (0 << 7);
- int phonemes_separator = ' ';
-
- int phoneme_conf = phoneme_options | (phonemes_separator << 8);
-
- FILE* f_phonemes_out = fopen(virtualFileName,"wb");
- if(!f_phonemes_out)
- return -1;
-
-
- espeak_SetPhonemeTrace(phoneme_conf, f_phonemes_out);
- espeak_Synth(aText, 0, 0, POS_CHARACTER, 0, 0, NULL, NULL);
- espeak_SetPhonemeTrace(0, NULL);
- fclose(f_phonemes_out);
-
- return 0;
- }
-
- long set_voice(
- const char* aName,
- const char* aLang=NULL,
- unsigned char aGender=0,
- unsigned char aAge=0,
- unsigned char aVariant = 0
- ) {
- long result = 0;
- if (aLang || aGender || aAge || aVariant) {
- espeak_VOICE props = { 0 };
- props.name = aName;
- props.languages = aLang;
- props.gender = aGender;
- props.age = aAge;
- props.variant = aVariant;
- result = espeak_SetVoiceByProperties(&props);
- } else {
- result = espeak_SetVoiceByName(aName);
- }
-
-
-
- current_voice = espeak_GetCurrentVoice();
-
- return result;
- }
-
- int getSizeOfEventStruct_() {
- return sizeof(espeak_EVENT);
- }
-
- const espeak_VOICE** voices;
- int samplerate;
- int rate;
- int pitch;
-
- private:
- espeak_VOICE* current_voice;
- };
-
- #include <glue.cpp>
|