Skip to content

Commit 5c887af

Browse files
author
matatonic
committed
2 parents e2dc57f + 43dbf43 commit 5c887af

6 files changed

+45
-11
lines changed

README.md

+17-4
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Details:
1818
* You can map your own [piper voices](https://rhasspy.github.io/piper-samples/) via the `voice_to_speaker.yaml` configuration file
1919
* Model `tts-1-hd` via [coqui-ai/TTS](https://github.com/coqui-ai/TTS) xtts_v2 voice cloning (fast, but requires around 4GB GPU VRAM)
2020
* Custom cloned voices can be used for tts-1-hd, See: [Custom Voices Howto](#custom-voices-howto)
21-
* 🌐 [Multilingual](#multilingual) support with XTTS voices
21+
* 🌐 [Multilingual](#multilingual) support with XTTS voices, the language is automatically detected if not set
2222
* [Custom fine-tuned XTTS model support](#custom-fine-tuned-model-support)
2323
* Configurable [generation parameters](#generation-parameters)
2424
* Streamed output while generating
@@ -30,6 +30,19 @@ If you find a better voice match for `tts-1` or `tts-1-hd`, please let me know s
3030

3131
## Recent Changes
3232

33+
Version 0.17.2, 2024-07-01
34+
35+
* fix -min image (re: langdetect)
36+
37+
Version 0.17.1, 2024-07-01
38+
39+
* fix ROCm (add langdetect to requirements-rocm.txt)
40+
* Fix zh-cn for xtts
41+
42+
Version 0.17.0, 2024-07-01
43+
44+
* Automatic language detection, thanks [@RodolfoCastanheira](https://github.com/RodolfoCastanheira)
45+
3346
Version 0.16.0, 2024-06-29
3447

3548
* Multi-client safe version. Audio generation is synchronized in a single process. The estimated 'realtime' factor of XTTS on a GPU is roughly 1/3, this means that multiple streams simultaneously, or `speed` over 2, may experience audio underrun (delays or pauses in playback). This makes multiple clients possible and safe, but in practice 2 or 3 simultaneous streams is the maximum without audio underrun.
@@ -58,7 +71,7 @@ Version 0.14.0, 2024-06-26
5871
Version 0.13.0, 2024-06-25
5972

6073
* Added [Custom fine-tuned XTTS model support](#custom-fine-tuned-model-support)
61-
* Initial prebuilt arm64 image support (Apple M-series, Raspberry Pi - MPS is not supported in XTTS/torch), thanks @JakeStevenson, @hchasens
74+
* Initial prebuilt arm64 image support (Apple M-series, Raspberry Pi - MPS is not supported in XTTS/torch), thanks [@JakeStevenson](https://github.com/JakeStevenson), [@hchasens](https://github.com/hchasens)
6275
* Initial attempt at AMD GPU (ROCm 5.7) support
6376
* Parler-tts support removed
6477
* Move the *.default.yaml to the root folder
@@ -88,7 +101,7 @@ Version 0.11.0, 2024-05-29
88101

89102
Version: 0.10.1, 2024-05-05
90103

91-
* Remove `runtime: nvidia` from docker-compose.yml, this assumes nvidia/cuda compatible runtime is available by default. thanks @jmtatsch
104+
* Remove `runtime: nvidia` from docker-compose.yml, this assumes nvidia/cuda compatible runtime is available by default. thanks [@jmtatsch](https://github.com/jmtatsch)
92105

93106
Version: 0.10.0, 2024-04-27
94107

@@ -318,7 +331,7 @@ tts-1-hd:
318331

319332
Multilingual cloning support was added in version 0.11.0 and is available only with the XTTS v2 model. To use multilingual voices with piper simply download a language specific voice.
320333

321-
Coqui XTTSv2 has support for 16 languages: English (`en`), Spanish (`es`), French (`fr`), German (`de`), Italian (`it`), Portuguese (`pt`), Polish (`pl`), Turkish (`tr`), Russian (`ru`), Dutch (`nl`), Czech (`cs`), Arabic (`ar`), Chinese (`zh-cn`), Japanese (`ja`), Hungarian (`hu`) and Korean (`ko`).
334+
Coqui XTTSv2 has support for multiple languages: English (`en`), Spanish (`es`), French (`fr`), German (`de`), Italian (`it`), Portuguese (`pt`), Polish (`pl`), Turkish (`tr`), Russian (`ru`), Dutch (`nl`), Czech (`cs`), Arabic (`ar`), Chinese (`zh-cn`), Hungarian (`hu`), Korean (`ko`), Japanese (`ja`), and Hindi (`hi`). When not set, an attempt will be made to automatically detect the language, falling back to English (`en`).
322335

323336
Unfortunately the OpenAI API does not support language, but you can create your own custom speaker voice and set the language for that.
324337

add_voice.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111

1212
parser.add_argument('sample', action='store', help="Set the wav sample file")
1313
parser.add_argument('-n', '--name', action='store', help="Set the name for the voice (by default will use the WAV file name)")
14-
parser.add_argument('-l', '--language', action='store', default="en", help="Set the language for the voice",
15-
choices=['en', 'es', 'fr', 'de', 'it', 'pt', 'pl', 'tr', 'ru', 'nl', 'cs', 'ar', 'zh-cn', 'ja', 'hu', 'ko'])
14+
parser.add_argument('-l', '--language', action='store', default="auto", help="Set the language for the voice",
15+
choices=['auto', 'en', 'es', 'fr', 'de', 'it', 'pt', 'pl', 'tr', 'ru', 'nl', 'cs', 'ar', 'zh-cn', 'ja', 'hu', 'ko', 'hi'])
1616
parser.add_argument('--openai-model', action='store', default="tts-1-hd", help="Set the openai model for the voice")
1717
parser.add_argument('--xtts-model', action='store', default="xtts", help="Set the xtts model for the voice (if using a custom model, also set model_path)")
1818
parser.add_argument('--model-path', action='store', default=None, help="Set the path for a custom xtts model")

requirements-rocm.txt

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ uvicorn
33
loguru
44
piper-tts
55
coqui-tts
6+
langdetect
67
# Creating an environment where deepspeed works is complex, for now it will be disabled by default.
78
#deepspeed
89
torch; --index-url https://download.pytorch.org/whl/rocm5.7; sys_platform == "linux"

requirements.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ uvicorn
33
loguru
44
piper-tts
55
coqui-tts[languages]
6+
langdetect
67
# Creating an environment where deepspeed works is complex, for now it will be disabled by default.
78
#deepspeed
89

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

15-
# ROCM (Linux only) - use requirements.amd.txt
16+
# ROCM (Linux only) - use requirements.amd.txt

speech.py

+21-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
from pydantic import BaseModel
1818
import uvicorn
1919

20-
2120
@contextlib.asynccontextmanager
2221
async def lifespan(app):
2322
yield
@@ -270,7 +269,21 @@ async def generate_speech(request: GenerateSpeechRequest):
270269
# Pipe the output from piper/xtts to the input of ffmpeg
271270
ffmpeg_args.extend(["-"])
272271

273-
language = voice_map.pop('language', 'en')
272+
language = voice_map.pop('language', 'auto')
273+
if language == 'auto':
274+
try:
275+
language = detect(input_text)
276+
if language not in [
277+
'en', 'es', 'fr', 'de', 'it', 'pt', 'pl', 'tr',
278+
'ru', 'nl', 'cs', 'ar', 'zh-cn', 'hu', 'ko', 'ja', 'hi'
279+
]:
280+
logger.debug(f"Detected language {language} not supported, defaulting to en")
281+
language = 'en'
282+
else:
283+
logger.debug(f"Detected language: {language}")
284+
except:
285+
language = 'en'
286+
logger.debug(f"Failed to detect language, defaulting to en")
274287

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

@@ -282,7 +295,11 @@ async def generate_speech(request: GenerateSpeechRequest):
282295
hf_generate_kwargs['enable_text_splitting'] = hf_generate_kwargs.get('enable_text_splitting', True) # change the default to true
283296

284297
if hf_generate_kwargs['enable_text_splitting']:
285-
all_text = split_sentence(input_text, language, xtts.xtts.tokenizer.char_limits[language])
298+
if language == 'zh-cn':
299+
split_lang = 'zh'
300+
else:
301+
split_lang = language
302+
all_text = split_sentence(input_text, split_lang, xtts.xtts.tokenizer.char_limits[split_lang])
286303
else:
287304
all_text = [input_text]
288305

@@ -387,6 +404,7 @@ def auto_torch_device():
387404
from TTS.tts.models.xtts import Xtts
388405
from TTS.utils.manage import ModelManager
389406
from TTS.tts.layers.xtts.tokenizer import split_sentence
407+
from langdetect import detect
390408

391409
if args.preload:
392410
xtts = xtts_wrapper(args.preload, device=args.xtts_device, unload_timer=args.unload_timer)

voice_to_speaker.default.yaml

+2-1
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,9 @@ tts-1-hd:
4646
model: xtts
4747
speaker: voices/shimmer.wav
4848
me:
49-
model: xtts_v2.0.2 # you can specify different xtts version
49+
model: xtts_v2.0.2 # you can specify an older xtts version
5050
speaker: voices/me.wav # this could be you
51+
language: auto
5152
enable_text_splitting: True
5253
length_penalty: 1.0
5354
repetition_penalty: 10

0 commit comments

Comments
 (0)