Michael Hu commited on
Commit
e50d013
·
1 Parent(s): bda4ba4

initial app file development

Browse files
Files changed (3) hide show
  1. README.md +42 -2
  2. app.py +77 -4
  3. requirements.txt +4 -0
README.md CHANGED
@@ -1,5 +1,5 @@
1
  ---
2
- title: Chatterbox
3
  emoji: 👁
4
  colorFrom: purple
5
  colorTo: pink
@@ -9,4 +9,44 @@ app_file: app.py
9
  pinned: false
10
  ---
11
 
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ title: Chatterbox Multilingual TTS Demo
3
  emoji: 👁
4
  colorFrom: purple
5
  colorTo: pink
 
9
  pinned: false
10
  ---
11
 
12
+ # Chatterbox Multilingual TTS Demo
13
+
14
+ This demo showcases the multilingual capabilities of the Chatterbox TTS model, supporting both English and Chinese languages.
15
+
16
+ ## Features
17
+
18
+ - Text-to-speech generation for English and Chinese
19
+ - Gradio web interface for easy interaction
20
+ - Real-time audio generation and playback
21
+ - Example texts for quick testing
22
+
23
+ ## Requirements
24
+
25
+ - Python 3.8 or higher
26
+ - Required Python packages (automatically installed by Hugging Face):
27
+ - chatterbox-tts
28
+ - gradio
29
+ - torchaudio
30
+ - torch
31
+
32
+ ## Usage
33
+
34
+ 1. Enter text in the input box
35
+ 2. Select the language (English or Chinese)
36
+ 3. Click "Generate Speech"
37
+ 4. Listen to the generated audio
38
+
39
+ ## Supported Languages
40
+
41
+ - English
42
+ - Chinese
43
+
44
+ ## Examples
45
+
46
+ The interface includes example texts for both languages to help you get started quickly.
47
+
48
+ ## Notes
49
+
50
+ - The first generation may take a moment as the model loads
51
+ - Subsequent generations will be faster
52
+ - For best results, use clear and properly punctuated text
app.py CHANGED
@@ -1,7 +1,80 @@
1
  import gradio as gr
 
 
 
 
 
2
 
3
- def greet(name):
4
- return "Hello " + name + "!!"
5
 
6
- demo = gr.Interface(fn=greet, inputs="text", outputs="text")
7
- demo.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
+ import torchaudio as ta
3
+ import torch
4
+ import tempfile
5
+ import os
6
+ from chatterbox.mtl_tts import ChatterboxMultilingualTTS
7
 
8
+ # Initialize the multilingual model
9
+ model = ChatterboxMultilingualTTS.from_pretrained(device="cuda" if torch.cuda.is_available() else "cpu")
10
 
11
+ def generate_speech(text, language):
12
+ """
13
+ Generate speech from text using Chatterbox multilingual TTS
14
+
15
+ Args:
16
+ text (str): Text to convert to speech
17
+ language (str): Language code ('en' for English, 'zh' for Chinese)
18
+
19
+ Returns:
20
+ str: Path to the generated audio file
21
+ """
22
+ # Map language codes to full names for Chatterbox
23
+ language_map = {
24
+ "English": "en",
25
+ "Chinese": "zh"
26
+ }
27
+
28
+ language_id = language_map.get(language, "en")
29
+
30
+ # Generate speech using Chatterbox
31
+ wav = model.generate(text, language_id=language_id)
32
+
33
+ # Save to a temporary file
34
+ with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as tmp_file:
35
+ ta.save(tmp_file.name, wav, model.sr)
36
+ return tmp_file.name
37
+
38
+ # Create Gradio interface
39
+ with gr.Blocks(title="Chatterbox Multilingual TTS Demo") as demo:
40
+ gr.Markdown("# Chatterbox Multilingual TTS Demo")
41
+ gr.Markdown("This demo uses Chatterbox to generate speech in English and Chinese.")
42
+
43
+ with gr.Row():
44
+ with gr.Column():
45
+ text_input = gr.Textbox(
46
+ label="Input Text",
47
+ placeholder="Enter text to convert to speech...",
48
+ lines=3
49
+ )
50
+ language_selection = gr.Radio(
51
+ choices=["English", "Chinese"],
52
+ value="English",
53
+ label="Language"
54
+ )
55
+ generate_btn = gr.Button("Generate Speech")
56
+
57
+ with gr.Column():
58
+ audio_output = gr.Audio(label="Generated Speech", type="filepath")
59
+
60
+ # Examples
61
+ gr.Examples(
62
+ examples=[
63
+ ["Hello, welcome to the Chatterbox multilingual demo. This is an English example.", "English"],
64
+ ["你好,欢迎来到Chatterbox多语言演示。这是一个中文示例。", "Chinese"]
65
+ ],
66
+ inputs=[text_input, language_selection],
67
+ outputs=audio_output,
68
+ fn=generate_speech,
69
+ cache_examples=True
70
+ )
71
+
72
+ # Connect the generate button to the function
73
+ generate_btn.click(
74
+ fn=generate_speech,
75
+ inputs=[text_input, language_selection],
76
+ outputs=audio_output
77
+ )
78
+
79
+ if __name__ == "__main__":
80
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ chatterbox-tts
2
+ gradio>=5.44.1
3
+ torchaudio
4
+ torch