Article
Yuri Marx · Feb 21 6m read

REST Service for Convert text to audio using IRIS and Python gTTS

Hi Community,

Imagine enabling your application to read text to your customer? This is now possible with the new IRIS feature, Embedded Python. With this new functionality IRIS can natively run any open source or commercial Python libraries natively. gTTS (https://pypi.org/project/gTTS/) is a free library that transforms text into audio using the Google Translate service.

How to

Just pass the text by parameter and gTTS returns an mp3 file with the text transformed into audio. That is, your application can play the audio of any text! See how to do it:

1. Go to https://openexchange.intersystems.com/package/IRIS-Text2Audio and Click Download button.

2. Clone/git pull the repo into any local directory

$ git clone https://github.com/yurimarx/iris-tts.git

3. Open a Docker terminal in this directory and run:

$ docker-compose build

4. Run the IRIS container:

$ docker-compose up -d 

5. Go to your Postman (or other similar REST client) and config the request like this image:

Request TTS input

6. Click send and get a response with a player to play the mp3 file, like picture above.

Behind the scenes

1. The Dockerfile install IRIS with Python and gTTS library

 
Dockerfile

2. A ClassMethod was created with Python language configured that uses gTTS to transform text into audio and record it in an mp3 file:

 
Python method to generate audio from text

3. A REST API in ObjectScript was created to expose Python functionality as a TTS microservice (very fancy!)

 
TTS REST Service

 

5
2 123
Discussion (2)2
Log in or sign up to continue

love it!!  I have previously said that I believe the most useful benefit of python for IRIS would be opening the gateway to python based libraries which do cool things.   this is an awesome example of that concept!!

Thanks! You right, I have other apps published on OEX to detect objects, encrypt, do geocoding, all using Python and IRIS.