Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411498 Posts in 69373 Topics- by 58428 Members - Latest Member: shelton786

April 25, 2024, 08:10:36 AM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)Speech Synthesizer
Pages: [1]
Print
Author Topic: Speech Synthesizer  (Read 679 times)
LazyCat2
Level 0
*


View Profile
« on: August 25, 2016, 01:01:17 PM »

eSpeak text to speech:
http://espeak.sourceforge.net/
https://en.wikipedia.org/wiki/ESpeak


Here is basic usage example and compiled libraries for Windows and Linux:
https://sourceforge.net/projects/brogueaudio/files/Brogue-SPEAK/eSPeak-examples.zip

I'm using it to make Brogue (a roguelike game) playable for blind people, but I imagine there are other reasons why you might want to add this to your game. Surprisingly there is very little information on the internet about how to use eSpeak library, and thus compiling it for Windows to work in asynchronous mode was quite tricky, so I think someone might find this zip above rather useful.

Anyway, once you have the library using it in your own code is super-easy:

Code:
#include <stdio.h>
#include <string.h>
#include "speak_lib.h"

void sayIt(char *voc, bool syncme)
{
    espeak_Cancel();
    espeak_Synth(voc, 100, 0, POS_CHARACTER, 0, 0, 0, 0);

    if(syncme)
        espeak_Synchronize();
}

int main()
{
    espeak_Initialize(AUDIO_OUTPUT_PLAYBACK, 1000, "./", 0);
    espeak_SetParameter(espeakRATE, 170, 0);

    char txt1[80]= "While I nodded, nearly napping, suddenly there came a tapping,";
    char txt2[80]= "As of some one gently rapping, rapping at my chamber door.";
    char txt3[80]= "...And the only word there spoken was the whispered word, \"Lenore?\"";

    sayIt(txt1, true);
    sayIt(txt2, true);
    sayIt(txt3, true);

    espeak_Terminate();
    return 0;
}

Windows compile: gcc main.cpp -o eSpeak.exe .\libespeak.dll
Linux compile: gcc main.cpp -o eSpeak -lespeak -lstdc++ -L./espeak-libs

Simple as that.

By the way, here is Brogue-SPEAK:
https://sourceforge.net/projects/brogueaudio/files/Brogue-SPEAK/Brogue174-SPEAKv03_win.zip
https://sourceforge.net/projects/brogueaudio/files/Brogue-SPEAK/Brogue174-SPEAKv03_lin.tar.gz


« Last Edit: August 25, 2016, 01:10:22 PM by LazyCat2 » Logged
Polly
Level 6
*



View Profile
« Reply #1 on: August 25, 2016, 02:42:51 PM »

Nice! Did a quick conversion of the header to ZGE ( project XML below ) and it worked without a hitch Smiley

Code:
<?xml version="1.0" encoding="iso-8859-1" ?>
<ZApplication Name="App" Caption="eSpeak" FileVersion="2">
  <OnLoaded>
    <ZExternalLibrary ModuleName="libespeak.dll" CallingConvention="1">
      <Source>
<![CDATA[int espeak_Cancel(){}
int espeak_Initialize(int output, int buflength, string path, int options){}
int espeak_IsPlaying(){}
int espeak_SetParameter(int parameter, int value, int relative){}
int espeak_Synth(string text, int size, int position, int position_type, int end_position, int flags, xptr unique_identifier, xptr user_data){}
int espeak_Terminate(){}]]>
      </Source>
    </ZExternalLibrary>
    <ZExpression>
      <Expression>
<![CDATA[espeak_Initialize(0, 1000, "./", 0);
espeak_SetParameter(1, 170, 0);
espeak_Cancel();
espeak_Synth("The quick brown fox jumps over the lazy dog", 256, 0, 1, 0, 0, null, null);]]>
      </Expression>
    </ZExpression>
  </OnLoaded>
  <OnClose>
    <ZExpression Expression="espeak_Terminate();"/>
  </OnClose>
</ZApplication>
Logged
Sik
Level 10
*****


View Profile WWW
« Reply #2 on: August 27, 2016, 08:56:44 PM »

On Windows I had used SAPI and on Linux I had used speech-dispatcher (both of which are quite easy to use, albeit platform specific).

The problem though is that all those libraries don't use the screen reader but instead voice on their own, and it becomes really annoying when you consider they tuned the screen readers specifically to how they use their computer (and often set them to absurdly high speeds, too), and yes there have been quite a bunch of complaints over this. The only way around this is talking to the screen readers directly sadly, though there are libraries to handle them for you (like Tolk, first one that comes to mind).

EDIT: whoops forgot Tolk is under the LGPL license. Make sure you know what you're doing if you use it =/ (especially these days where the most popular platforms are the most locked down ones)
« Last Edit: August 27, 2016, 09:07:24 PM by Sik » Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic