This is the Server Side of my interview application in Smarkio.
Basically, a REST API that consists of converting text to speech using the IBM Watson Cloud platform.
Client-Side available: Here
- Node.js - A JavaScript Interpreter
- TypeScript - A Superset for JavaScript
- MySQL - A Relational Database
- Knex.js - A SQL Query Builder
- Docker - A Container Creator
- Docker Compose - A Container Orchestrator
-
- A IBM Watson Cloud Account -> IBM-Register
- On your IBM account, you will need to use the Text To Speech (TTS) service.
- Clone this repo with:
$ git clone https://github.com/matheus2x/smarkio-case-server.git
- Move yourself to the appropriate directory:
$ cd smarkio-case-server
- Rename
.env.example
to.env
-
In your
.env
file, add credentials for your IBM-Cloud Account (don't change the others environment vars):TTS_API_KEY= // REQUIRED TTS_URL= // REQUIRED
-
Run
$ docker-compose up --build -d
to build docker-compose -
Run
$ npm run populate
to run migrations
- To installing dependencies, run:
$ npm install
- In your
.env
file, change values with your credentials:
// Server
NODE_PORT=3333 // OPTIONAL
// MySQL
MYSQL_HOST= // without docker= REQUIRED
MYSQL_USER= // OPTIONAL
MYSQL_PASS= // OPTIONAL
MYSQL_DB= // without docker= REQUIRED
// IBM Cloud
TTS_API_KEY= // REQUIRED
TTS_URL= // REQUIRED
- In your MYSQL, create a DB (with the same name as in your
.env
file):
CREATE DATABASE someDatabase;
- Run
$ npm run build
to compile ts build bundle - Run
$ npm run knex:migrate
to run migrations - Run
$ npm run start
to start server
If you've done Everything so far, you can now Start the Client-Side.
Attention: Omit the braces {}
from examples. They indicate variable values
Method: POST
Route: http://localhost:{NODE_PORT}/tts
Request Body:
{
"comment": String,
"voiceLang": String // "1" to pt-br and "2" to en-us
}
Response:
{
"id": Number,
"comment": String,
"audio": String // path to use
}
Method: GET
Route: http://localhost:{NODE_PORT}/uploads/speech-{commentID}.mp3
Output: audio.mp3 bynary file
Example: speech-1.mp3
Listen audio in Vocaroo: https://voca.ro/1kSLOdtoUecV
Method: GET
Route: http://localhost:{NODE_PORT}/tts
Response:
[
{
"id": Number,
"comment": String,
"audio": String
},
{
"id": Number,
"comment": String,
"audio": String
},
...
]