@@ -50,23 +50,31 @@ public: | |||
espeak_SetSynthCallback(NULL); | |||
} | |||
void set_voice( | |||
long set_voice( | |||
const char* aName, | |||
const char* aLang, | |||
const char* aLang=NULL, | |||
unsigned char aGender=0, | |||
unsigned char aAge=0, | |||
unsigned char aVariant = 0 | |||
) { | |||
espeak_VOICE props = { 0 }; | |||
props.name = aName; | |||
props.languages = aLang; | |||
props.gender = aGender; | |||
props.age = aAge; | |||
props.variant = aVariant; | |||
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); | |||
} | |||
// This way we don't need to allocate the name/lang strings to the heap. | |||
// Instead, we store the actual global voice. | |||
espeak_SetVoiceByProperties(&props); | |||
current_voice = espeak_GetCurrentVoice(); | |||
return result; | |||
} | |||
int getSizeOfEventStruct_() { |
@@ -53,7 +53,7 @@ interface eSpeakNGWorker { | |||
void eSpeakNGWorker(); | |||
void synth_(DOMString aText, VoidPtr aCallback); | |||
long getSizeOfEventStruct_(); | |||
void set_voice(DOMString aName, DOMString aLang, optional octet gender=0, optional octet age=0, optional octet aVariant=0); | |||
long set_voice(DOMString aName, DOMString aLang, optional octet gender=0, optional octet age=0, optional octet aVariant=0); | |||
[Const] attribute espeak_VOICE[] voices; | |||
readonly attribute long samplerate; | |||
attribute long rate; |
@@ -159,7 +159,7 @@ function speak() { | |||
tts.set_pitch(Number(document.getElementById('pitch').value)); | |||
console.log(' Setting pitch... done'); | |||
console.log(' Setting voice...'); | |||
tts.set_voice.apply(tts, (document.getElementById('voice').value.split(','))); | |||
tts.set_voice(document.getElementById('voice').value); | |||
console.log(' Setting voice... done'); | |||
var now = Date.now(); | |||
@@ -232,16 +232,17 @@ function initializeDemo() { | |||
var sel = document.getElementById('voice'); | |||
var index = 0; | |||
for (voice of result) { | |||
for (lang of voice.languages) { | |||
var opt = document.createElement('option'); | |||
opt.text = voice.name + ' (' + lang.name + ')'; | |||
opt.value = [voice.name, lang.name]; | |||
console.log('Adding voice: ' + opt.text); | |||
sel.add(opt); | |||
if (voice.name === 'default') { | |||
opt.id = 'default-voice'; | |||
opt.selected = true; | |||
} | |||
var opt = document.createElement('option'); | |||
var languages = voice.languages.map(function(lang) { | |||
return lang.name; | |||
}).join(", "); | |||
opt.text = voice.name + ' (' + languages + ')'; | |||
opt.value = voice.identifier; | |||
console.log('Adding voice: ' + opt.text); | |||
sel.add(opt); | |||
if (voice.name === 'default') { | |||
opt.id = 'default-voice'; | |||
opt.selected = true; | |||
} | |||
} | |||
console.log('Leaving cb2'); |