Text To Speech¶
This service generates a sound file (”.wav”) from a any given text in the following languages:
- English (US)
- English (GB)
- German
- Spanish (ES)
- French
- Italian
Getting Started¶
Using Angus python SDK:
# -*- coding: utf-8 -*-
import angus.client
conn = angus.client.connect()
service = conn.services.get_service('text_to_speech', version=1)
job = service.process({'text': "Hi guys, how are you today?", 'lang' : "en-US"})
### The output wav file is available as compressed (zlib), base64 string.
sound = job.result["sound"]
Input¶
The function process()
takes a dictionary formatted as follows:
{'text' : "Hello guys",
'lang' : "en-US"}
text
: a string containing the text to be synthesized.lang
: the code of the language to be used for synthesis. Languages currently available are:- English (US) :
en-US
- English (GB) :
en-GB
- German :
de-DE
- Spanish (ES) :
es-ES
- French :
fr-FR
- Italian :
it-IT
- English (US) :
Output¶
Events will be pushed to your client following the below format:
{
"status" : 201,
"sound" : "'eJzsvHdUFNm6N1yhEzQ ... jzf//+T/jj/A8b0r/9"
}
status
: the http status code of the request.sound
: contains the synthesized sound file (.wav) as a compressed (zlib), base64 string. Please refer to the code sample below of how to decode it in Python.
Code Sample¶
This code sample uses Angus text_to_speech
service to synthesize “hi guys, how are you today?”.
# -*- coding: utf-8 -*-
import angus.client
import base64
import zlib
import subprocess
def decode_output(sound, filename):
sound = base64.b64decode(sound)
sound = zlib.decompress(sound)
with open(filename, "wb") as f:
f.write(sound)
conn = angus.client.connect()
service = conn.services.get_service('text_to_speech', version=1)
job = service.process({'text': "Hi guys, how are you today?", 'lang' : "en-US"})
### The output wav file is available as compressed (zlib), base64 string.
### Here, the string is decoded and played back by Linux "aplay".
decode_output(job.result["sound"], "output.wav")
subprocess.call(["/usr/bin/aplay", "./output.wav"])