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

Added Docker Setup #16

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 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
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ RUN apt-get update && apt-get install -y curl unzip && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
RUN pip install --no-cache-dir -r ./requirements.txt
RUN mkdir audio
RUN mkdir -p audio
EXPOSE 8124
CMD ["python", "./engine.py"]
31 changes: 18 additions & 13 deletions engine.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
import sys
import os
sys.path.insert(0, os.getcwd()+'/glados_tts')

import torch
from utils.tools import prepare_text
from scipy.io.wavfile import write
import time

from glados import tts_runner

current_dir = os.getcwd()
sys.path.insert(0, current_dir+'/glados_tts')

print("\033[1;94mINFO:\033[;97m Initializing TTS Engine...")

Expand All @@ -20,6 +16,9 @@ def glados_tts(text, key=False, alpha=1.0):
else:
output_file = ('audio/GLaDOS-tts-temp-output.wav')

# Ensure the directory exists
os.makedirs(os.path.dirname(output_file), exist_ok=True)

glados.run_tts(text, alpha).export(output_file, format = "wav")
return True

Expand All @@ -32,6 +31,8 @@ def glados_tts(text, key=False, alpha=1.0):
CACHE = True

from flask import Flask, request, send_file
import threading
import time
import urllib.parse
import shutil

Expand All @@ -49,7 +50,7 @@ def synthesize(text):
filename = filename.replace("!", "")
filename = filename.replace("°c", "degrees celcius")
filename = filename.replace(",", "")+".wav"
file = os.getcwd()+'/audio/'+filename
file = current_dir+'/audio/'+filename

# Check for Local Cache
if(os.path.isfile(file)):
Expand All @@ -62,20 +63,24 @@ def synthesize(text):
# Generate New Sample
key = str(time.time())[7:]
if(glados_tts(line, key)):
tempfile = os.getcwd()+'/audio/GLaDOS-tts-temp-output-'+key+'.wav'
tempfile = current_dir+'/audio/GLaDOS-tts-temp-output-'+key+'.wav'

# If the line isn't too long, store in cache
if(len(line) < 200 and CACHE):
shutil.move(tempfile, file)
else:
# Remove the temp file after 5 seconds
def remove_file():
time.sleep(5)
try:
os.remove(tempfile)
except Exception as error:
app.logger.error("Error removing or closing downloaded file handle", error)
threading.Thread(target=remove_file).start()
return send_file(tempfile)
os.remove(tempfile)

return send_file(file)

else:
return 'TTS Engine Failed'

cli = sys.modules['flask.cli']
cli.show_server_banner = lambda *x: None
app.run(host="0.0.0.0", port=PORT)