Skip to content

Commit

Permalink
✨ make final fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ZamDimon committed Jun 29, 2024
1 parent f8693da commit db44b76
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
Binary file added .DS_Store
Binary file not shown.
11 changes: 5 additions & 6 deletions src/api/main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import TypeAlias, Tuple, Any
from pathlib import Path
import logging
import hashlib
import flask
Expand All @@ -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
Expand All @@ -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:
Expand All @@ -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)
Expand Down
6 changes: 5 additions & 1 deletion src/cloner/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
"""
Expand Down Expand Up @@ -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,
Expand Down
Binary file removed test.wav
Binary file not shown.

0 comments on commit db44b76

Please sign in to comment.