eaysu commited on
Commit
a6bbc99
·
1 Parent(s): fcd0b14

initial commit

Browse files
Files changed (2) hide show
  1. app.py +45 -0
  2. requirements.txt +4 -0
app.py ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoProcessor, BarkModel
3
+ import scipy
4
+
5
+ # Load the Bark model and processor
6
+ processor = AutoProcessor.from_pretrained("suno/bark-small")
7
+ model = BarkModel.from_pretrained("suno/bark-small")
8
+
9
+ # Function to generate speech
10
+ def generate_speech(text, voice_preset):
11
+ # Process the input text with the selected voice preset
12
+ inputs = processor(text, voice_preset=voice_preset)
13
+ # Generate audio
14
+ audio_array = model.generate(**inputs)
15
+ audio_array = audio_array.cpu().numpy().squeeze()
16
+ # Return the audio as a tuple with the sample rate for Gradio's audio component
17
+ return (model.generation_config.sample_rate, audio_array)
18
+
19
+ # Gradio app setup
20
+ with gr.Blocks() as app:
21
+ gr.Markdown("# Turkish Text-to-Speech with Bark")
22
+ gr.Markdown("Enter text, select a Turkish voice preset, and click 'Generate Voice' to play the generated audio.")
23
+
24
+ # Input text box for user to type text
25
+ text_input = gr.Textbox(label="Enter Text in Turkish", placeholder="Merhaba, bugün bir yerlere gidelim mi?")
26
+
27
+ # Dropdown for selecting voice preset
28
+ voice_preset_input = gr.Dropdown(
29
+ ["v2/tr_speaker_0", "v2/tr_speaker_1", "v2/tr_speaker_2", "v2/tr_speaker_3",
30
+ "v2/tr_speaker_4", "v2/tr_speaker_5", "v2/tr_speaker_6",
31
+ "v2/tr_speaker_7", "v2/tr_speaker_8", "v2/tr_speaker_9"],
32
+ label="Select Turkish Voice Preset"
33
+ )
34
+
35
+ # Audio output component for playing generated audio
36
+ audio_output = gr.Audio(label="Generated Voice", type="numpy")
37
+
38
+ # Button to trigger the generation
39
+ generate_button = gr.Button("Generate Voice")
40
+
41
+ # When the button is clicked, call the generate_speech function
42
+ generate_button.click(generate_speech, inputs=[text_input, voice_preset_input], outputs=audio_output)
43
+
44
+ # Launch the Gradio app
45
+ app.launch()
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ transformers
2
+ scipy
3
+ torch
4
+ gradio