abderrahimbrighal commited on
Commit
2eb8b5d
·
verified ·
1 Parent(s): d6a15ae

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -10
app.py CHANGED
@@ -1,14 +1,33 @@
1
- from transformers import pipeline
2
- from IPython.display import Audio
3
 
4
- # Initialize the text-to-speech pipeline with the desired model
5
- pipe = pipeline("text-to-speech", model="kotoba-tech/kotoba-speech-v0.1")
6
 
7
- # Input text
8
- text = "Don't count the days, make the days count."
 
9
 
10
- # Generate speech from text
11
- narrated_text = pipe(text)
 
 
12
 
13
- # Display the audio
14
- Audio(narrated_text["audio"], rate=narrated_text["sampling_rate"])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from melo.api import TTS
 
2
 
3
+ # Speed is adjustable
4
+ speed = 1.0
5
 
6
+ # CPU is sufficient for real-time inference.
7
+ # You can set it manually to 'cpu' or 'cuda' or 'cuda:0' or 'mps'
8
+ device = 'auto' # Will automatically use GPU if available
9
 
10
+ # English
11
+ text = "Did you ever hear a folk tale about a giant turtle?"
12
+ model = TTS(language='EN', device=device)
13
+ speaker_ids = model.hps.data.spk2id
14
 
15
+ # American accent
16
+ output_path = 'en-us.wav'
17
+ model.tts_to_file(text, speaker_ids['EN-US'], output_path, speed=speed)
18
+
19
+ # British accent
20
+ output_path = 'en-br.wav'
21
+ model.tts_to_file(text, speaker_ids['EN-BR'], output_path, speed=speed)
22
+
23
+ # Indian accent
24
+ output_path = 'en-india.wav'
25
+ model.tts_to_file(text, speaker_ids['EN_INDIA'], output_path, speed=speed)
26
+
27
+ # Australian accent
28
+ output_path = 'en-au.wav'
29
+ model.tts_to_file(text, speaker_ids['EN-AU'], output_path, speed=speed)
30
+
31
+ # Default accent
32
+ output_path = 'en-default.wav'
33
+ model.tts_to_file(text, speaker_ids['EN-Default'], output_path, speed=speed)