REST Service for Convert text to audio using IRIS and Python gTTS
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.
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:
- Method: POST
- URL: http://localhost:52773/iris-tts/texttoaudio
- Body: raw (try any text sentence)
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
2. A ClassMethod was created with Python language configured that uses gTTS to transform text into audio and record it in an mp3 file:
3. A REST API in ObjectScript was created to expose Python functionality as a TTS microservice (very fancy!)