QTextToSpeech---setVoice
-
Hi, I am new to QT and I am using QTextToSpeech for genearting voice in my desktop app. I tried setLocale and its working fine if I change it to any region. Now I am using setVoice to change the voice but its not working. Can someone suggest me how to acheive this.
myvoice->setLocale(QLocale("en_US")); myvoice->setVoice(QVoice::Gender('Female')); -
Hi and welcome to devnet,
Which version of Qt are you using ?
On which platform ? -
Can you provide a minimal compilable application that reproduces your issue so people can also test on their side.
On a side note, shouldn't that be
myvoice->setVoice(QVoice::Female);?
Second note,myvoiceis a bit confusing as it makes it look like a QVoice object but is likely a QTextSpeech object, correct ? -
I tried it like you said setVoice(QVoice::Female);
and Yes myvoice or _tts is QTextToSpeech object as you said.
_tts = new QTextToSpeech(this);
_tts->setLocale(QLocale("en_US"));
_tts->setVoice(QVoice::Female);Attached is the screenshot of the issue I am facing.


-
I tried it like you said setVoice(QVoice::Female);
and Yes myvoice or _tts is QTextToSpeech object as you said.
_tts = new QTextToSpeech(this);
_tts->setLocale(QLocale("en_US"));
_tts->setVoice(QVoice::Female);Attached is the screenshot of the issue I am facing.


@Aqib
I know nothing about Qt voice/speech. But worrying as it is to have to question @SGaist's answer:myvoice->setVoice(QVoice::Female)As per the error message you are being shown, QTextToSpeech::setVoice(const QVoice &voice) requires a
QVoiceparameter, butQVoice::Femaleis a QVoice::Gender.I note that
QVoicedoes not even have/document a (public) constructor? Maybe you are supposed to use QVector<QVoice> QTextToSpeech::availableVoices() const to accessQVoices for each available one, and pick one whose QVoice::Gender QVoice::gender() const== QVoice::Female?? Pure guesswork on my part though!UPDATE
I have just gone try this, and that's exactly how it works: you must pick one of theavailableVoices(), look at theirgender()to pick one.Under my Ubuntu 20.04 with the voice package installed I get 5 UK voices. Regional variations, but all are
"Unknown Gender" "Other Age". They are all male, and adult. No female! So pretty sexist (and ageist) for 2022 ;-) probably better on Windows. -
@JonB good catch ! Regarding my answer, there's likely some automatic conversion going on somewhere.
As for the available voices on Linux, did you check what was installed with your backend ? There might simply be sound packs missing or something like that.
-
@JonB good catch ! Regarding my answer, there's likely some automatic conversion going on somewhere.
As for the available voices on Linux, did you check what was installed with your backend ? There might simply be sound packs missing or something like that.
@SGaist
My backend is fine, thank you very much :) It's the default Ubuntu voice, using thoseapt -get installI posted in another question. I was only playing with it because of this question. But it would be nicer if it offered a female voice, let me know if you actually know what you'd need for Ubuntu. -
Which backend are you using ?
-
@SGaist
I didsudo apt-get install qtspeech5-speechd-plugin. I think it's calledspeechd. Is that the right answer to "which backend"?Oh and per https://forum.qt.io/topic/75426/qt-speech-plug-in/20
And the speech engine can be installed with:
sudo apt-get install speech-dispatcherIt said that was already installed.
-
@SGaist
I didsudo apt-get install qtspeech5-speechd-plugin. I think it's calledspeechd. Is that the right answer to "which backend"?Oh and per https://forum.qt.io/topic/75426/qt-speech-plug-in/20
And the speech engine can be installed with:
sudo apt-get install speech-dispatcherIt said that was already installed.