File size: 1,798 Bytes
42a53f6
 
 
 
 
 
 
 
 
65a2eb1
42a53f6
 
65a2eb1
42a53f6
65a2eb1
42a53f6
 
 
 
 
 
 
 
 
 
65a2eb1
 
42a53f6
4db2518
65a2eb1
 
 
 
 
15d3e5b
42a53f6
 
 
65a2eb1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import gradio as gr
from transformers import AutoProcessor, BarkModel
import scipy

############################
### Variable Declaration ###
############################

# -- UI Variables
ui_input_voice_preseter=gr.Dropdown(
    ["v2/en_speaker_0","v2/en_speaker_9"], label="Voice Presenter"
)
ui_input_filename=gr.Textbox(label="Input WAV Filename")
ui_input_text=gr.Textbox(lines=22,label="Input Text")
ui_output=gr.Audio(label="Output")

# -- Model Variables
processor = AutoProcessor.from_pretrained("suno/bark")
model = BarkModel.from_pretrained("suno/bark")

############################
### Processing Functions ###
############################

# -- On Click of Submit Button in UI
def submit(voice_preseter, filename, input_text):
   print("Hello World")
   
   inputs = processor(input_text, voice_preset=voice_preseter) 
   audio_array = model.generate(**inputs)
   audio_array = audio_array.cpu().numpy().squeeze() 
   sample_rate = model.generation_config.sample_rate
   scipy.io.wavfile.write(filename, rate=sample_rate, data=audio_array) 
   
   retun gr.Audio(source=[os.path.join(os.path.dirname(__file__),filename])     

############################
###### Main Program ########
############################
ui_input_filename = "Hello uh ... [clears throat], \
        Bark is a transformer-based text-to-speech model proposed by Suno AI. \
        This voice is auto generated"

# -- Start of Program - Main
def main():
    demo = gr.Interface(
                        fn=submit, 
                        inputs=[ui_input_voice_preseter,ui_input_filename,ui_input_text], 
                        outputs=ui_output,
                        allow_flagging="never"
                    ) 
    demo.queue().launch()

# -- Calling Main Function
if __name__ == '__main__':
    main()