Skip to content

Commit

Permalink
Merge pull request #29 from RodolfoCastanheira/main
Browse files Browse the repository at this point in the history
detecting and using multiple languages automatically (xtts)
  • Loading branch information
matatonic authored Jul 1, 2024
2 parents a99b196 + be02887 commit 54ad8a1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ uvicorn
loguru
piper-tts
coqui-tts[languages]
langdetect
# Creating an environment where deepspeed works is complex, for now it will be disabled by default.
#deepspeed

Expand All @@ -12,4 +13,4 @@ torchaudio; sys_platform != "darwin"
torch; --index-url https://download.pytorch.org/whl/cpu; sys_platform == "darwin"
torchaudio; --index-url https://download.pytorch.org/whl/cpu; sys_platform == "darwin"

# ROCM (Linux only) - use requirements.amd.txt
# ROCM (Linux only) - use requirements.amd.txt
18 changes: 16 additions & 2 deletions speech.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from openedai import OpenAIStub, BadRequestError, ServiceUnavailableError
from pydantic import BaseModel
import uvicorn

from langdetect import detect

@contextlib.asynccontextmanager
async def lifespan(app):
Expand Down Expand Up @@ -270,7 +270,21 @@ async def generate_speech(request: GenerateSpeechRequest):
# Pipe the output from piper/xtts to the input of ffmpeg
ffmpeg_args.extend(["-"])

language = voice_map.pop('language', 'en')
language = voice_map.pop('language', 'auto')
if language == 'auto':
try:
language = detect(input_text)
if language not in [
'en', 'es', 'fr', 'de', 'it', 'pt', 'pl', 'tr',
'ru', 'nl', 'cs', 'ar', 'zh-cn', 'hu', 'ko', 'ja', 'hi'
]:
logger.debug(f"Detected language {language} not supported, defaulting to en")
language = 'en'
else:
logger.debug(f"Detected language: {language}")
except:
language = 'en'
logger.debug(f"Failed to detect language, defaulting to en")

comment = voice_map.pop('comment', None) # ignored.

Expand Down

0 comments on commit 54ad8a1

Please sign in to comment.