Details
Description
The QTextToSpeech class has the say(const QString &text) that starts synthesizing the speech asynchronously, and reads the text to the default audio output device.
It is a very convenient method, but lacks flexibility in certain cases.
I suggest to add a method that just synthesize the text and write to a file
synthesize(const QString &text, QIODevice * output)
The application is free to use the output in the best way the developer think, play the audio with the QAudioSink immediately, save and reuse later. It would also be possible to add the audio to a video file and play the video/audio together as a multimedia object.
The change open up new possibilities and the QTextToSpeech say function already has all in place for synthesizing. The changes are minimal.
It will require an event that notify that the file is ready.
If you implement the new method I would also suggest to also provide the ability to use the SSML a mentioned in https://www.qt.io/blog/qt-speech-coming-to-qt-6.4
SSML is a standard that is used by many text to speech engine.
I'm not a specialist of API design, but for must use case, it would be sufficient to provide a way to specify that the text to synthesize is plain text or SSML text. An application should take care to prepare a formatted SSML text. It could be useful if you need to read a date or number.
You could provide a parameter to specify if the text is SSML
synthesize(const QString &text, QTextToSpeech::textType type,QIODevice * output)
or have a specific method
synthesizeSsml(const QString &text, QIODevice * output)
With the here proposed additions the QTextToSpeech would become more flexible and powerful.
Attachments
For Gerrit Dashboard: QTBUG-109837 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
455218,24 | Add QTextToSpeech::synthesize to produce PCM data rather than audio | dev | qt/qtspeech | Status: MERGED | +2 | 0 |