Hi, i’m trying the TTS for my game, but the voice doesn’t change beside my efforts, any clue?
Hi @ayrin !
I’m currently working on TTS right now as well, are you using the web speech api?
Yes @Codeknight999 i’m using that, i have tried both firefox and chrome but it’s so awful and unchanging
I’ve been running into the same issue as well, I think I know how to fix it though, what is your current code for the TTS?
I have
var settings = this.ttsSettings[giver];
var gender = settings.gender;
var pitch = settings.pitch;
var rate = settings.rate;
this.player.speak(textq, giver, gender, pitch, rate);
And
this.ttsSettings = {
"Ranger guild": { gender: "male", pitch: 0.9 },
"Warriors guild": { gender: "male", pitch: 0.75 },
"Thieves guild": { gender: "female", pitch: 1.1 },
"Emporium": { gender: "male", pitch: 0.6, rate: 0.9 },
"Inn": { gender: "female", pitch: 1.2 },
"Herbalist": { gender: "male", pitch: 0.85 },
"Blacksmith": { gender: "male", pitch: 0.7 }
};
sorry forgot this
Player.prototype.speak = function(text, npcType) {
if (!text || text.length === 0) return;
var lang = this.lang || "en";
var voice = this.NewInv.script.questSheet.getVoiceForNPC(npcType, lang);
if (!voice) return;
var utterance = new SpeechSynthesisUtterance(text);
utterance.voice = voice;
speechSynthesis.speak(utterance);
};
Btw @Codeknight999 i tried this but don’t get any response
const voices = window.speechSynthesis.getVoices();
console.log("Available voices:", voices);
Check this link about the voices:
I also don’t think that gender is a thing you can pass as a setting, but you can select different voices with different genders.
I looked into that and run the code, it gives me just 4 voices 3 in italian and 1 in english (female), my idea to work on pitch tochange the tone didn’t work at all
i made a big mistake, didn’t update the script in player that’s why it didn’t work, so dumb
this is the script, but no improvements
Player.prototype.speak = function(text, npcType, gender, pitch, rate) {
if (!text || text.length === 0) return;
var lang = this.lang || "en";
// Get voice for NPC / giver
var voice = this.NewInv.script.questSheet.getVoiceForNPC(npcType, lang, gender);
if (!voice) {
// fallback: use first available voice for the language
var voices = speechSynthesis.getVoices().filter(v => v.lang.startsWith(lang));
if (voices.length > 0) voice = voices[0];
}
if (!voice) return;
var utterance = new SpeechSynthesisUtterance(text);
utterance.voice = voice;
// Apply optional pitch and rate
if (typeof pitch === "number") utterance.pitch = pitch; // 0 to 2
if (typeof rate === "number") utterance.rate = rate; // 0.1 to 10
speechSynthesis.speak(utterance);
};
Btw, firefox has less voices than chrome…i will try to run my game on chrome and let you know the results
Yes in chrome works better, not really a perfect solution, but at least i have a male voice. the alternatives are 3rd parties apis. like azure, polly or google.
Tomorrow I can take a look and try and get a better fix, I don’t have Firefox to test on there though.
Sorry for this late reply,
I have a project going for testing now, here is the link:
https://playcanvas.com/editor/scene/2391240
On Google I am getting 210 voices, but I am not getting them to play. I believe the issue is with the sound needing to play on user context (i.e, clicking)
If your goal is to have consistent voices, I would try this.
No prob my reply is late also, i want just few variants and male and female voices, but seems the browser native text to speech is no good, or i put the text to speech as optional in the game options, so also if it’s ugly who cares, and maybe slowly i will look into one of those external things.