Conversation
|
Seconded. Also, options to increase/decrease the speed of TTS narration would be great if possible, since the default speed is slower than most people speak 🙂 |
you got it |
notimaginative
left a comment
There was a problem hiding this comment.
I tested it on Mac and confirmed everything was still working. Apart from the issues noted obviously. I'd like to check and test the Linux changes as well and will do that when I have a bit more time.
However, one desperately needed addition is the ability to actually test the voice changes before saving them.
| static SCP_vector<SCP_string> cached_voices; | ||
| static bool voices_cached = false; |
There was a problem hiding this comment.
This really doesn't need to happen. It's a complete waste of memory. The voices should be cached of course, but that should happen when and where it's needed, not globally at startup.
I'm only marking that issue here, but it applies to win and linux versions as well.
There was a problem hiding this comment.
this is needed for imgui, otherwise it would call the getvoices() at every frame.
There is any any to detect when we are out of the settings systems to clear memory? Ideally you would call it once when you enter to cache it and empty on exit.
There was a problem hiding this comment.
ingame_options_close() can be used for the F3 settings screen, but I'm not sure how that interacts with SCPUI. Simple in theory, but what I didn't realize until now is that the options builder prints the current values to the log, which means it has to load all of this stuff at startup without the in-game options screen ever being active. Which also means that we can't just initialize the voices in in game_options_init().
We might be able to cache the name of the currently active voice and use that whenever it requests the id of the active voice. The options could be changed so that only ttsvoice_enumerator() gets the whole list of voices and builds a <int, SCP_string> pair vector and then display doesn't have to look it up. I believe the display resolution option does it like that so take a look in 2d.cpp for an example. You'd still have to get the list of voices every frame, but only once a frame, and only when on the settings screen, so you could probably get away with not caching it.
Hopefully something like that would work. If not then I think it's going to require changes beyond the scope of this PR. If that's the case then we'll just have to accept it as-is and have a look at improving OptionBuilder in the future to make dealing with this stuff easier.
| // 180 wpm = normal | ||
| float rate = 180.0f * (rate_percent / 100.0f); |
There was a problem hiding this comment.
The base speaking rate varies by the voice in use so you can't use a general default value and have it sound right. I recommend using something similar to the attached diff which gets the default voice rate when a voice is set and uses that as the value for these calculations.
This applies to the Mac voice stuff only, but the Linux and Windows versions may need something similar, along with the value cap for safety.
|
Regarding testing; The options UI framework doesn't really have a nice way to set that up as a separate control. I'd recommend carving out a special case for this option's selector to play a test whenever the value changes. |
|
|
||
| SPDConnection* connection = spd; | ||
| if ( !Speech_init ) { | ||
| connection = p_spd_open("fso_voice_list", "client", nullptr, SPD_MODE_SINGLE); |
There was a problem hiding this comment.
This needs to use the same client and connection names as the p_spd_open() call in speech_init().
| endif() | ||
| elseif(APPLE) | ||
| # it should just work | ||
| elseif(UNIX) |
There was a problem hiding this comment.
UNIX includes any Unix-like OS, such as BSD, macOS, Cygwin, and others. If Speech Dispatcher or any system calls/headers used by the code are not generally available outside of Linux then please narrow down the check here.
If the code is intended to be used or available on platforms other than just Linux then I'd recommend renaming speech_linux.cpp to support that notion.
| IF(WIN32 OR APPLE) | ||
| OPTION(FSO_USE_SPEECH "Use text-to-speach libraries" ON) | ||
| ENDIF(WIN32 OR APPLE) | ||
| OPTION(FSO_USE_SPEECH "Use text-to-speach libraries" ON) |
There was a problem hiding this comment.
If speech isn't available outside of Windows, Mac, and Linux then this should still be behind a guard, or at least default to OFF if it's not one of those three platforms.
| elseif (UNIX) | ||
| add_file_folder("Sound" | ||
| ${file_root_sound} | ||
| sound/speech_linux.cpp |
There was a problem hiding this comment.
Same issue using UNIX here as mentioned in the FindSpeech.cmake comments applies here as well.
| auto rate = static_cast<signed int>(rate_percent - 100.0f); | ||
| if (rate < -100) | ||
| rate = -100; | ||
| if (rate > 100) |
There was a problem hiding this comment.
Should be else if (...), or preferably just use CAP(rate, -100, 100);.
| SPDVoice** voices = p_spd_list_synthesis_voices(connection); | ||
|
|
||
| for (int i = 0; voices[i] != nullptr; i++) { | ||
| SCP_string lang = voices[i]->language; |
There was a problem hiding this comment.
Why? There's no need to allocate memory for this. Just use strncmp() on voices[i]->language directly.
| } | ||
| } | ||
|
|
||
| SPDVoice** voices = p_spd_list_synthesis_voices(connection); |
There was a problem hiding this comment.
voices can be null so anything referencing it must be inside of an if (voices) {...} guard.
| SCP_string lang = voices[i]->language; | ||
| // There are too many we cant add them all | ||
| // Only add English voices | ||
| if(lang.find("en") == 0) { |
There was a problem hiding this comment.
It would probably be best if this filtered based on the games current language index (in this case: "en", "de", "fr", "pl") rather than limiting it exclusively to English.
There was a problem hiding this comment.
i was thinking about that, but it would not be correct as de version would only load DE voices that would not work with any mission on knossos that arent in german. Like, all of them.
This may need to trought into it then, getting getting the list of voices langs installed in system to filter and add some sort of selector based on that is more complicated. And it would need to be done for all OS.
There was a problem hiding this comment.
Hmm, I guess I should have tested that. I'm sort of going off of how it works on Mac, since it will translate the text into the TTS language you've set (based on voice). And I don't know if the voice synthesis with Speech Dispatcher works the same way. If not then obviously the point is moot and how you're currently doing it is probably the safest option.
There was a problem hiding this comment.
Ideally you would also want a language combo box to filter the voices. It is probably posible to populate it using the getvoices code. Ill look at this after fixing the other issues.
I played around with this a bit, but it doesn't look like there's a way to do it. It's easy enough to add a test command to the change listener but that's only called when changes are saved. There doesn't appear to be any current mechanism to deal with control changes when they happen. I assume we'll have to push the test feature down the road, extend options manager to have such functionality, then circle back and add it for TTS. |
|
I did the requested changes. taylor when you have the time please take a look. two things to add:
Also, normally you are not going to want to use the espeak-ng voices, they are terrible, so Linux users should be able to remove the espeak-ng backend and install a neural one like PiperTTS to speech-dispatcher. I havent tested that myselft but the point of using speech-dispatcher is that it should work with any TTS backend. |
The objectives of this pr are:
Add TTS Speech options to ingame options settings. Incliding voice selection, voice rate, volume settings and select places were TTS is used
Add TTS Speech support to Linux OS by using speech-dispatcher/libspeechd-dev, this is done used dlopen and a small implementation of the lib types. In this way there is not additional dependency for compiling or in runtime, if speech-dispatcher is not installed on host OS, the speech system just fails to init.
Separate the speech system cpps into diferent files for each platform, copying the way it was done for mac, this is clearer and will make it easier to add other platforms, like android in the future.
Sanitize text was moved to an earlier stage, to fsspeech.cpp, to avoid having to repeat this bit of code in every implementation.
Note:
I may have broken mac tts with these changes and i have no way to test it.