diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..4adaf84 Binary files /dev/null and b/.DS_Store differ diff --git a/src/api/main.py b/src/api/main.py index e10dd26..606f775 100644 --- a/src/api/main.py +++ b/src/api/main.py @@ -1,4 +1,5 @@ from typing import TypeAlias, Tuple, Any +from pathlib import Path import logging import hashlib import flask @@ -15,6 +16,8 @@ Response: TypeAlias = Tuple[dict, int] # Just a type alias for the response +DEFAULT_PATH = 'lele.wav' + def run_api(_voice_cloner: VoiceCloner) -> None: """ Runs the API for serving feature extraction method @@ -31,10 +34,6 @@ def jsonify_error(err: errs.ErrorResponse) -> Response: json_err, status_code = err return flask.jsonify(json_err), status_code - # Returning an error if got a wrong method - if flask.request.method != "POST": - return jsonify_error(errs.INVALID_METHOD) - # Asserting that the request has the necessary data def validate_request() -> bool: if "data" not in flask.request.json: @@ -55,14 +54,14 @@ def validate_request() -> bool: # Cloning the voice try: - voice = voice_cloner.clone_voice(text) + voice = voice_cloner.save_voice_locally(text, Path(DEFAULT_PATH)) except Exception as exception: logging.error(f"Failed to process the image: {exception}") return jsonify_error(errs.INTERNAL_ERROR) # Updating that the claim was submitted try: - return flask.send_file(voice, as_attachment=True, mimetype='.wav', download_name='lele.wav') + return flask.send_file(Path('../../' + DEFAULT_PATH), as_attachment=True, mimetype='audio/wav', download_name='lele.wav') except Exception as exception: logging.error(f"Failed while finalizing the request: {exception}") return jsonify_error(errs.INTERNAL_ERROR) diff --git a/src/cloner/main.py b/src/cloner/main.py index 367e70f..a8c1d3f 100644 --- a/src/cloner/main.py +++ b/src/cloner/main.py @@ -4,6 +4,7 @@ from pathlib import Path from typing import Any from TTS.api import TTS +import os # Internal imports from voices.voices import get_speaker_wav @@ -16,7 +17,7 @@ def __init__(self) -> None: Initializes the VoiceCloner class """ - self._tts = TTS('xtts') + self._tts = TTS('xtts-v2') def clone_voice(self, text: str) -> Any: """ @@ -55,6 +56,9 @@ def save_voice_locally(self, text: str, path: Path) -> None: - None """ + if os.path.exists(str(path)): + os.remove(str(path)) + start_time = time.time() # Recoding how much tome it takes to clone the voice voice = self._tts.tts_to_file( text=text, diff --git a/test.wav b/test.wav deleted file mode 100644 index 3a67c74..0000000 Binary files a/test.wav and /dev/null differ