Fix API for voice conversion

This commit is contained in:
Eren Gölge 2023-04-10 13:32:16 +02:00
parent 30109af2a0
commit 5bd1fb6b2c
1 changed files with 28 additions and 5 deletions

View File

@ -85,7 +85,7 @@ class CS_API:
self.headers = {"Content-Type": "application/json", "Authorization": f"Bearer {self.api_token}"} self.headers = {"Content-Type": "application/json", "Authorization": f"Bearer {self.api_token}"}
if not self.api_token: if not self.api_token:
raise ValueError( raise ValueError(
"No API token found for 🐸Coqui Studio voices - https://coqui.ai.\n" "No API token found for 🐸Coqui Studio voices - https://coqui.ai \n"
"Visit 🔗https://app.coqui.ai/account to get one.\n" "Visit 🔗https://app.coqui.ai/account to get one.\n"
"Set it as an environment variable `export COQUI_STUDIO_TOKEN=<token>`\n" "Set it as an environment variable `export COQUI_STUDIO_TOKEN=<token>`\n"
"" ""
@ -274,7 +274,10 @@ class TTS:
self.model_name = None self.model_name = None
if model_name: if model_name:
self.load_tts_model_by_name(model_name, gpu) if "tts_models" in model_name:
self.load_tts_model_by_name(model_name, gpu)
elif "voice_conversion_models" in model_name:
self.load_vc_model_by_name(model_name, gpu)
if model_path: if model_path:
self.load_tts_model_by_path( self.load_tts_model_by_path(
@ -565,19 +568,39 @@ class TTS:
def voice_conversion( def voice_conversion(
self, self,
sourve_wav: str, source_wav: str,
target_wav: str, target_wav: str,
): ):
"""Voice conversion with FreeVC. Convert source wav to target speaker. """Voice conversion with FreeVC. Convert source wav to target speaker.
Args:``
source_wav (str):
Path to the source wav file.
target_wav (str):`
Path to the target wav file.
"""
wav = self.voice_converter.voice_conversion(source_wav=source_wav, target_wav=target_wav)
return wav
def voice_conversion_to_file(
self,
source_wav: str,
target_wav: str,
file_path: str = "output.wav",
):
"""Voice conversion with FreeVC. Convert source wav to target speaker.
Args: Args:
source_wav (str): source_wav (str):
Path to the source wav file. Path to the source wav file.
target_wav (str): target_wav (str):
Path to the target wav file. Path to the target wav file.
file_path (str, optional):
Output file path. Defaults to "output.wav".
""" """
wav = self.synthesizer.voice_conversion(source_wav=sourve_wav, target_wav=target_wav) wav = self.voice_conversion(source_wav=source_wav, target_wav=target_wav)
return wav save_wav(wav=wav, path=file_path, sample_rate=self.voice_converter.vc_config.audio.output_sample_rate)
return file_path
def tts_with_vc(self, text: str, language: str = None, speaker_wav: str = None): def tts_with_vc(self, text: str, language: str = None, speaker_wav: str = None):
"""Convert text to speech with voice conversion. """Convert text to speech with voice conversion.