shukdevdatta123 commited on
Commit
e47cdda
·
verified ·
1 Parent(s): 6d7fea6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -19
app.py CHANGED
@@ -23,40 +23,50 @@ torch.load = original_load
23
 
24
  def generate_speech(reference_audio, text):
25
  """
26
- Generate speech audio mimicking the voice from the reference audio using Bark.
27
 
28
  Parameters:
29
- reference_audio (str): Filepath to the uploaded voice sample.
30
  text (str): Text to convert to speech.
31
 
32
  Returns:
33
- str: Path to the generated audio file
34
  """
35
- # Generate speech using the reference audio and text
36
- audio_array = generate_audio(text, history_prompt=reference_audio)
 
37
 
38
- # Create a temporary file to save the audio
39
- temp_file = tempfile.NamedTemporaryFile(suffix=".wav", delete=False)
40
- temp_file_path = temp_file.name
41
- # Save the audio to the temporary file
42
- write_wav(temp_file_path, SAMPLE_RATE, audio_array)
43
- temp_file.close()
44
 
45
  return temp_file_path
46
 
47
  # Build the Gradio interface
48
- with gr.Blocks(title="Voice Cloning TTS with Bark") as app:
49
- gr.Markdown("## Voice Cloning Text-to-Speech with Bark")
50
- gr.Markdown("Upload a short voice sample in English, then enter text to hear it in your voice!")
 
 
 
51
 
52
- with gr.Row():
53
- audio_input = gr.Audio(type="filepath", label="Upload Your Voice Sample (English)")
54
- text_input = gr.Textbox(label="Enter Text to Convert to Speech", placeholder="e.g., I love chocolate")
 
 
 
 
 
 
 
55
 
56
- generate_btn = gr.Button("Generate Speech")
57
  audio_output = gr.Audio(label="Generated Speech", interactive=False)
58
 
59
- # Connect the button to the generation function
 
60
  generate_btn.click(
61
  fn=generate_speech,
62
  inputs=[audio_input, text_input],
 
23
 
24
  def generate_speech(reference_audio, text):
25
  """
26
+ Generate speech audio using a pre-defined speaker.
27
 
28
  Parameters:
29
+ reference_audio (str): Path to uploaded audio (ignored in this version).
30
  text (str): Text to convert to speech.
31
 
32
  Returns:
33
+ str: Path to the generated audio file.
34
  """
35
+ # Use a pre-defined speaker since custom voice cloning isn't supported
36
+ history_prompt = "v2/en_speaker_6" # Pre-defined speaker ID
37
+ audio_array = generate_audio(text, history_prompt=history_prompt)
38
 
39
+ # Save the audio to a temporary file
40
+ with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as temp_file:
41
+ write_wav(temp_file.name, SAMPLE_RATE, audio_array)
42
+ temp_file_path = temp_file.name
 
 
43
 
44
  return temp_file_path
45
 
46
  # Build the Gradio interface
47
+ with gr.Blocks(title="Text-to-Speech with Bark") as app:
48
+ gr.Markdown("## Text-to-Speech with Bark")
49
+ gr.Markdown(
50
+ "Enter text to hear it in a pre-defined voice. "
51
+ "Custom voice cloning from uploaded audio is not supported in this version."
52
+ )
53
 
54
+ # Input components
55
+ audio_input = gr.Audio(
56
+ type="filepath",
57
+ label="Upload Your Voice Sample (English, Ignored)",
58
+ visible=True # Kept for future functionality, but ignored
59
+ )
60
+ text_input = gr.Textbox(
61
+ label="Enter Text to Convert to Speech",
62
+ placeholder="e.g., I love chocolate"
63
+ )
64
 
65
+ # Output component
66
  audio_output = gr.Audio(label="Generated Speech", interactive=False)
67
 
68
+ # Button to trigger generation
69
+ generate_btn = gr.Button("Generate Speech")
70
  generate_btn.click(
71
  fn=generate_speech,
72
  inputs=[audio_input, text_input],