I cannot express how happy I am that speech is now so easy in ZIM. I mean the text to speech.
The example code works nice, but I have a question.
My target market is "dutch speaking".
When I run the code below, then I can select a dutch (Nederlands) voice and the text to speech works fine, but I would like to be able to iterate over the list of available voices and filter the ones that are og language "nl-NL" and "nl-BE" which are the Dutch ones.
I tried this code
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>ZIM 016 - Speech Talk with Voices - Code Creativity</title>
<script type=module>
import zim from "https://zimjs.org/cdn/016/zim";
// See Docs under Frame for FIT, FILL, FULL, and TAG
// caves - from Spaghetti Guitar In Space by Peter Surdoval
new Frame(FIT, 1024, 768, interstellar, black, ready);
function ready() {
// let user pick a voice
const speech = new Speech();
console.log (speech);
new Button({label:"TALK"}).center().mov(0,-120).tap(()=>{
speech.talk("Welke provincie is gekleurd? Typ de correcte naam. Proficiat, dit was inderdaad West-Vlaanderen.", list?list.text:null);
});
let list;
if (!M) {
speech.on("voiceschanged", ()=>{ // must wait for voices to be loaded
if (list) list.dispose(); // seems to run only once but just in case
list = new List(500,300,speech.voices,6).center().mov(0,120);
S.update();
});
}
}
</script>
<meta name="viewport" content="width=device-width, user-scalable=no" />
</head>
<body></body>
</html>
The line where I console.log (speech) does return me in console some kind of object. I shows Qo.speech..............
When I expand this in console, then I see it contains voiceLanguages, voiceLookup and even voiceObject with all kinds of valuable info about the speech.
Only problem is that I don't seem to find a way to get to that data. It always returns me undefined data.
How could I iterate over this data in the speech object and console log every voice (the name) where the language is "nl-BE" or "nl-NL" ?
If I can do that, then I could prefilter the voices and select a dutch voice + if the user wants to change voice I would only present them the dutch voices.
Hopefully somebody can help a little?
Thank you,
Bart