Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a server for the Singaporean Voice #12

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Binary file not shown.
Binary file not shown.
Binary file not shown.
1 change: 0 additions & 1 deletion saylah-mobile
Submodule saylah-mobile deleted from 5deb70
15 changes: 15 additions & 0 deletions server/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# 1
FROM python:3.7

# 2
RUN pip install numpy Flask gunicorn malaya malaya-speech pydub

# 3
COPY src/ /app
WORKDIR /app

# 4
ENV PORT 8080

# 5
CMD exec gunicorn --bind :$PORT --workers 1 --threads 8 app:app
25 changes: 25 additions & 0 deletions server/src/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from flask import Flask, jsonify, send_file, request, abort
import os
import time
import malaya_speech
from pydub import AudioSegment
from io import BytesIO
import numpy as np


app = Flask(__name__)


@app.route('/', methods=['POST'])
def speakSinglish(text):
if not request.json or not 'text' in request.json: abort(400)
mp3 = BytesIO()
AudioSegment((np.iinfo(np.int16).max * vocoder(tacotron.predict(request.json["text"])["universal-output"])).astype(np.int16).tobytes(), frame_rate=22050, sample_width=2, channels=1).export(mp3, format="mp3", bitrate="320k")
mp3.seek(0)
return send_file(mp3, as_attachment=True, attachment_filename='test.mp3', mimetype='audio/mpeg')


if __name__ == '__main__':
tacotron = malaya_speech.tts.tacotron2(model='female-singlish')
vocoder = malaya_speech.vocoder.melgan(model='universal-1024')
app.run(debug=True, host='0.0.0.0', port=int(os.environ.get('PORT', 8080)))
14 changes: 14 additions & 0 deletions test-server/test-malaya.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import numpy as np
import matplotlib.pyplot as plt
from pydub import AudioSegment
from io import BytesIO
import malaya_speech

tacotron = malaya_speech.tts.tacotron2(model='female-singlish')
vocoder = malaya_speech.vocoder.melgan(model='universal-1024')

mp3 = BytesIO()
AudioSegment((np.iinfo(np.int16).max * vocoder(tacotron.predict("Hello World, this is a test of a Singaporean accent. Currently we only have a female singlish accent but let's see how it goes.")["universal-output"])).astype(np.int16).tobytes(), frame_rate=22050, sample_width=2, channels=1).export(mp3, format="mp3", bitrate="320k")
mp3.seek(0)

print(mp3.read())