QtSpeech, say “Hello World!”

I am glad to announce new small project that got first release – QtSpeech.
This is library providing Qt-like interface to system TTS (text-to-speech) engines to allow your application to say “Hello World!”.

Current API is very simple.
First you need to include <QtSpeech>. Then if your application just needed to say something synchronously (execution will wait in the point until speech is finished) you can use such code:

#include <QtSpeech>
QtSpeech voice;
voice.say("Hello World!");

If you would like to do this in asynchronous way (so your application is not blocked meanwhile) just use tell() call:

QtSpeech * voice = new QtSpeech(this);
voice->tell("Hello asynchronous world!");

If you need to invoke a slot at the end, use:

voice->tell("Hello!", this, SLOT(onSpeechFinished()));

Also you have possibility to get list of voices and choose voice from available in your system:

QtSpeech::VoiceNames vs = QtSpeech::names()

Current implementation support Windows using SAPI and Mac. I have plans to extend API to include more functionality but will try to choose what is common on all platforms.

Link to repository in Gitorius: http://gitorious.org/qt-speech

UPDATE: Unix/Linux got implementation too! Based on Festival, so only English at the moment, but it is a great start to have TTS working in Qt applications too in Linux systems!

This entry was posted in Blog, Projects, Qt, QtSpeech, Research, TTS. Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.
  • Nano

    You should consider using speech-dispatcher (http://www.freebsoft.org/speechd) on Linux. The eco System there is so fractured you shouldn’t expect a specific Synthesizer to be present. Afaik Speech dispatcher is currently the most common/stable way to add TTS capability to Linux applications.

  • yshurik

    It looks like speech-dispatcher (http://www.freebsoft.org/speechd) can not be used. It has GPL license, not LGPL, so choosing it as used library will limit usage of QtSpeech only to GPL applications which is not appropriate. QtSpeech is licensed as LGPL and I do not want to change it.

  • bassem

    can this work on mobile devices as well .. i need to build TTS apps on Symbian devices and couldn’t find something to start with

  • yshurik

    bassem: not a problem I guess – I just got working say() call using Festival. You may need to create right packaging for Festival on your Symbian device.

  • bassem

    i’ll work on it and i’ll notify you in case i reached good result

    i tried running the project on OSX and looped on all the available voices to let them speak , but all voices were spoken using the first voice , did U face this problem ?

  • yshurik

    bassem: sure, you forgot to pass VoiceName to QtSpeech constructor

  • bassem

    you’re completely right :)
    i fixed it and all the voices worked , thanks alot

    i’ll work on packaging festival for symbian for the next couple of days and once i reach something i’ll notify U.

    Any hints about the packaging process ? or even where to look for info about it ?

  • yshurik

    bassem: now to get Festival prepared for QtSpeech just run “get-festival.sh”. It will download and build tts engine in “festival” folder. Then QtSpeech for unix/linux can be built.

  • vernice

    Hi, yshurik! it works well on ubuntu, it’s wonderful! but I want to run TTS on MeeGo. Can you give some advice about how to begin? Thanks.

  • yshurik

    You just need a way to build Festival on MeeGo – as it is built, then everything should be straight to link with QtSpeech

  • mathi

    i followed the steps given in get-festival.sh and installed festival and speech tools.now if try to make QtSpeech.pro,there is no such folder.where is that?

  • Alexei Vinidiktov

    Hi, yshurik! Thanks for creating this library!

    I have a problem and a question.

    1. If I call the tell method a second time while the first tell method invocation is still working (that is still speaking) my app crashes.

    2. How can I make the voice stop in the middle of it speaking?

    I’m running Windows 8, Qt 4.8.0, Visual Studio 2010.


  • Alexei Vinidiktov

    I’ve managed to fix the problem with the crash and I figured out how to make it stop speaking.

    As I was calling the tell method without providing an object or a slot, I had to add this code in the tell method to make the crash go away (void QtSpeech::tell(QString text, QObject * obj, const char * slot) const):

    if (obj != 0L && slot != 0L)


    I also had to add the flag SPF_PURGEBEFORESPEAK to the line:

    SysCall( d->voice->Speak( w_text.w, SPF_ASYNC | SPF_IS_NOT_XML | SPF_PURGEBEFORESPEAK, 0), LogicError);

    Without it I couldn’t make the tell method stop speaking.

    Now to stop speaking I can simply call the tell method with an empty string as a parameter.

    The whole method now looks like this:

    void QtSpeech::tell(QString text, QObject * obj, const char * slot) const
    if (obj != 0L && slot != 0L)
    if (d->waitingFinish)
    throw LogicError(Where+”Already waiting to finish speech”);

    d->onFinishObj = obj;
    d->onFinishSlot = slot;
    if (obj && slot)
    connect(const_cast(this), SIGNAL(finished()), obj, slot);

    d->waitingFinish = true;

    Private::WCHAR_Holder w_text(text);
    SysCall( d->voice->Speak( w_text.w, SPF_ASYNC | SPF_IS_NOT_XML | SPF_PURGEBEFORESPEAK, 0), LogicError);

  • yshurik

    Alexei Vinidiktov: I am considering adding stop()/skip() methods to the library, but as I have appropriate logic to do this for mac and windows, I see some troubles of having same for festival on unixes, anyway it should be investigated first.

  • yshurik

    mathi: get-festival.sh does not install into os, but it prepares everything in “festival” folder – just in same location (QtSpeech folder), so it should be ready for linking when you build QtSpeech lib. See QtSpeech.pri, section “unix:!mac”, that has all references what to include/link. Then you can check what is not right in your case.

  • shiven

    can anyone tell me the steps to get this library and integrate it in my code i want to make a Qt based GUI app. for voice to text conversion

  • yshurik

    there is a link in post to gitorious repository

  • ismet

    i get following error when built qt application on ubuntu, What could be the reason?nneditline.c:(.text+0x7ab5): undefined reference to `tgetstr’neditline.c:-1: error: undefined reference to `tgetstr’

  • Oleg

    There are no uses of tgetstr in QtSpeech.

  • Enzo

    hi, i try to use this library with qt 4.7.4 on Windows server 2003, but when i compile my project i have many errors with Microsoft speech sdk…where I wrong?

  • XtremeTechnoSoftware

    I have the same problem as you.nDid you find how to solve the problem?

  • Enzo

    my problem was because i used mingw compiler instead of visual c++ compiler…

  • XtremeTechnoSoftware

    plz can you tell how i can change mingw compiler for visual c++

  • Oleg

    Guess that if you would like to use mingw, then you need a way to link versus libs in “C:/Program Files/Microsoft Speech SDK 5.1/Lib/i386” in some way

  • truongle

    I get the following error when buid qt application on ubuntu. what could be the reason?nn:-1: error: cannot find -lasoundn:-1: error: collect2: ld returned 1 exit status

  • truongle

    i have the same problem as you. Did you find how to solve the problem?

  • Manus Battersby

    hi, I’m using ubuntu version 10.04 LTS.nntrying to compile speech tools using gcc.nnafter i configure and make i get this error at the end.nnmake[1]: *** [ch_lab] Error 1nmake: *** [main] Error 2nnwhen i test it displays this error.nnmake[3]: *** [xml_example] Error 1nxml example status: FAILEDnmake[2]: *** [xml_module_rebuild] Error 1nndoes anyone know what i’m doing wrong.?

  • Manus Battersby

    Worked it out,,, the path in the makefile was incorrect.nseems to be working fine now.

Clef two-factor authentication