rahgadda commited on
Commit
65a2eb1
·
1 Parent(s): 42a53f6

Initial Draft

Browse files
Files changed (1) hide show
  1. voice.py +30 -6
voice.py CHANGED
@@ -7,12 +7,12 @@ import scipy
7
  ############################
8
 
9
  # -- UI Variables
10
- ui_input_type=gr.Dropdown(
11
  ["v2/en_speaker_0","v2/en_speaker_9"], label="Voice Presenter"
12
  )
13
- ui_input_filename=gr.Textbox(label="wav filename")
14
  ui_input_text=gr.Textbox(lines=22,label="Input Text")
15
- ui_output=gr.Textbox(lines=22,label="Output")
16
 
17
  # -- Model Variables
18
  processor = AutoProcessor.from_pretrained("suno/bark")
@@ -23,10 +23,34 @@ model = BarkModel.from_pretrained("suno/bark")
23
  ############################
24
 
25
  # -- On Click of Submit Button in UI
26
- def submit(type, input_text):
27
- ui_output=""
28
 
 
 
 
 
 
 
 
29
 
30
  ############################
31
  ###### Main Program ########
32
- ############################
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
  ############################
8
 
9
  # -- UI Variables
10
+ ui_input_voice_preseter=gr.Dropdown(
11
  ["v2/en_speaker_0","v2/en_speaker_9"], label="Voice Presenter"
12
  )
13
+ ui_input_filename=gr.Textbox(label="Input WAV Filename")
14
  ui_input_text=gr.Textbox(lines=22,label="Input Text")
15
+ ui_output=gr.Audio(label="Output")
16
 
17
  # -- Model Variables
18
  processor = AutoProcessor.from_pretrained("suno/bark")
 
23
  ############################
24
 
25
  # -- On Click of Submit Button in UI
26
+ def submit(voice_preseter, filename, input_text):
27
+ print("Hello World")
28
 
29
+ inputs = processor(input_text, voice_preset=voice_preseter)
30
+ audio_array = model.generate(**inputs)
31
+ audio_array = audio_array.cpu().numpy().squeeze()
32
+ sample_rate = model.generation_config.sample_rate
33
+ scipy.io.wavfile.write(filename, rate=sample_rate, data=audio_array)
34
+
35
+ retun gr.Audio(source=[os.path.join(os.path.dirname(__file__),filename)
36
 
37
  ############################
38
  ###### Main Program ########
39
+ ############################
40
+ ui_input_filename = "Hello uh ... [clears throat], \
41
+ Bark is a transformer-based text-to-speech model proposed by Suno AI. \
42
+ This voice is auto generated"
43
+
44
+ # -- Start of Program - Main
45
+ def main():
46
+ demo = gr.Interface(
47
+ fn=submit,
48
+ inputs=[ui_input_voice_preseter,ui_input_filename,ui_input_text],
49
+ outputs=ui_output,
50
+ allow_flagging="never"
51
+ )
52
+ demo.queue().launch()
53
+
54
+ # -- Calling Main Function
55
+ if __name__ == '__main__':
56
+ main()