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.

28 Comments

  1. Nano
    Posted February 10, 2011 at 18:28 | Permalink

    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.

  2. yshurik
    Posted February 10, 2011 at 18:59 | Permalink

    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.

  3. bassem
    Posted February 12, 2011 at 04:29 | Permalink

    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

  4. yshurik
    Posted February 13, 2011 at 00:53 | Permalink

    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.

  5. bassem
    Posted February 13, 2011 at 01:25 | Permalink

    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 ?

  6. yshurik
    Posted February 13, 2011 at 13:47 | Permalink

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

  7. bassem
    Posted February 15, 2011 at 20:04 | Permalink

    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 ?

  8. yshurik
    Posted February 22, 2011 at 23:29 | Permalink

    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.

  9. vernice
    Posted March 3, 2011 at 16:09 | Permalink

    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.

  10. yshurik
    Posted March 3, 2011 at 17:55 | Permalink

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

  11. mathi
    Posted April 7, 2012 at 06:37 | Permalink

    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?

  12. Alexei Vinidiktov
    Posted April 8, 2012 at 09:49 | Permalink

    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.

    Thanks!

  13. Alexei Vinidiktov
    Posted April 8, 2012 at 10:22 | Permalink

    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;
    const_cast(this)->startTimer(100);
    }

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

  14. yshurik
    Posted April 8, 2012 at 11:26 | Permalink

    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.

  15. yshurik
    Posted April 8, 2012 at 12:02 | Permalink

    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.

  16. shiven
    Posted April 18, 2013 at 06:18 | Permalink

    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

  17. yshurik
    Posted April 18, 2013 at 20:59 | Permalink

    there is a link in post to gitorious repository

  18. ismet
    Posted August 22, 2013 at 09:58 | Permalink

    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’

  19. Oleg
    Posted August 22, 2013 at 10:17 | Permalink

    There are no uses of tgetstr in QtSpeech.

  20. Enzo
    Posted September 11, 2013 at 09:04 | Permalink

    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?

  21. XtremeTechnoSoftware
    Posted September 26, 2013 at 14:16 | Permalink

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

  22. Enzo
    Posted September 28, 2013 at 08:37 | Permalink

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

  23. XtremeTechnoSoftware
    Posted October 4, 2013 at 19:25 | Permalink

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

  24. Oleg
    Posted October 4, 2013 at 20:54 | Permalink

    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

  25. truongle
    Posted February 6, 2014 at 19:52 | Permalink

    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

  26. truongle
    Posted February 6, 2014 at 20:29 | Permalink

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

  27. Manus Battersby
    Posted February 1, 2015 at 07:32 | Permalink

    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.?

  28. Manus Battersby
    Posted February 2, 2015 at 00:21 | Permalink

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

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>