aheedsajid commited on
Commit
8ad3de5
·
verified ·
1 Parent(s): e19b042

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -33
app.py CHANGED
@@ -29,7 +29,6 @@ async def get_voices():
29
  f"{voice['ShortName']} ({voice['Gender']}, {voice['Locale']})"
30
  for voice in english_voices
31
  ]
32
-
33
  return formatted_voices
34
 
35
  def extract_voice_name(voice_string):
@@ -49,21 +48,20 @@ async def create_podcast_version(data, speaker_name, speaker_voice, title):
49
  os.makedirs(temp_dir)
50
 
51
  try:
52
- combined_version = AudioSegment.empty()
53
 
54
  for i, entry in enumerate(data['conversation']):
55
  if 'speakertext' in entry:
56
  temp_file = f'{temp_dir}/speaker_{i}.mp3'
57
  await generate_audio(entry['speakertext'], speaker_voice, temp_file)
58
  audio = AudioSegment.from_file(temp_file)
59
- combined_version += audio
60
  os.remove(temp_file)
61
 
62
- output_path = f"{safe_title}_{speaker_name.lower()}.mp3"
63
- combined_version.export(output_path, format="mp3")
64
-
65
- return output_path, temp_dir
66
 
 
67
  except Exception as e:
68
  if os.path.exists(temp_dir):
69
  shutil.rmtree(temp_dir)
@@ -87,7 +85,7 @@ def generate_podcast(title, channel_name, speaker_name, speaker_voice):
87
  ]
88
  }}
89
 
90
- give 36 sentences.
91
  """,
92
  request=os.getenv('API_REQUEST'),
93
  param_3=0.5,
@@ -111,7 +109,7 @@ def generate_podcast(title, channel_name, speaker_name, speaker_voice):
111
  else:
112
  raise ValueError("Could not parse JSON from response")
113
 
114
- audio_path, temp_dir = asyncio.run(
115
  create_podcast_version(
116
  podcast_data,
117
  speaker_name,
@@ -123,16 +121,15 @@ def generate_podcast(title, channel_name, speaker_name, speaker_voice):
123
  if os.path.exists(temp_dir):
124
  shutil.rmtree(temp_dir)
125
 
126
- return [audio_path, podcast_data]
127
-
128
  except Exception as e:
129
  return [None, f"Error: {str(e)}"]
130
 
131
  with gr.Blocks(theme=gr.themes.Soft()) as interface:
132
  available_voices = asyncio.run(get_voices())
133
 
134
- gr.Markdown("# Easy Podcast")
135
- gr.Markdown("Generate a podcast monologue on any topic. Choose a voice and customize speaker details to create your perfect podcast.<br>To use elevelabs voices or cloned voices, or to automate the podcast video creation with avatar contact me at aheedsajid@gmail.com<br>Support me USDT (TRC-20) (TAe7hsSVWtMEYz3G5V1UiUdYPQVqm28bKx)")
136
 
137
  with gr.Row():
138
  with gr.Column():
@@ -147,8 +144,6 @@ with gr.Blocks(theme=gr.themes.Soft()) as interface:
147
  value="WeePakistan",
148
  show_label=True
149
  )
150
-
151
- with gr.Row():
152
  with gr.Column():
153
  speaker_name = gr.Textbox(
154
  label="Speaker Name",
@@ -156,31 +151,27 @@ with gr.Blocks(theme=gr.themes.Soft()) as interface:
156
  value="Andrew",
157
  show_label=True
158
  )
159
- speaker_voice = gr.Dropdown(
160
- choices=available_voices,
161
- value=next((v for v in available_voices if "Andrew" in v), available_voices[0]),
162
- label="Speaker Voice",
163
- info="Select voice for the speaker"
164
- )
 
 
165
 
166
  generate_btn = gr.Button("Generate Podcast", variant="primary")
167
 
168
- audio_output = gr.Audio(label="Generated Audio")
 
 
169
  conversation_json = gr.JSON(label="Generated Conversation")
170
 
171
  generate_btn.click(
172
  fn=generate_podcast,
173
- inputs=[
174
- title,
175
- channel_name,
176
- speaker_name,
177
- speaker_voice
178
- ],
179
- outputs=[
180
- audio_output,
181
- conversation_json
182
- ]
183
  )
184
 
185
  if __name__ == "__main__":
186
- interface.launch()
 
29
  f"{voice['ShortName']} ({voice['Gender']}, {voice['Locale']})"
30
  for voice in english_voices
31
  ]
 
32
  return formatted_voices
33
 
34
  def extract_voice_name(voice_string):
 
48
  os.makedirs(temp_dir)
49
 
50
  try:
51
+ speaker_version = AudioSegment.empty()
52
 
53
  for i, entry in enumerate(data['conversation']):
54
  if 'speakertext' in entry:
55
  temp_file = f'{temp_dir}/speaker_{i}.mp3'
56
  await generate_audio(entry['speakertext'], speaker_voice, temp_file)
57
  audio = AudioSegment.from_file(temp_file)
58
+ speaker_version += audio
59
  os.remove(temp_file)
60
 
61
+ speaker_path = f"{safe_title}_{speaker_name.lower()}_only.mp3"
62
+ speaker_version.export(speaker_path, format="mp3")
 
 
63
 
64
+ return speaker_path, temp_dir
65
  except Exception as e:
66
  if os.path.exists(temp_dir):
67
  shutil.rmtree(temp_dir)
 
85
  ]
86
  }}
87
 
88
+ give 36 sentences for the speaker.
89
  """,
90
  request=os.getenv('API_REQUEST'),
91
  param_3=0.5,
 
109
  else:
110
  raise ValueError("Could not parse JSON from response")
111
 
112
+ speaker_path, temp_dir = asyncio.run(
113
  create_podcast_version(
114
  podcast_data,
115
  speaker_name,
 
121
  if os.path.exists(temp_dir):
122
  shutil.rmtree(temp_dir)
123
 
124
+ return [speaker_path, podcast_data]
 
125
  except Exception as e:
126
  return [None, f"Error: {str(e)}"]
127
 
128
  with gr.Blocks(theme=gr.themes.Soft()) as interface:
129
  available_voices = asyncio.run(get_voices())
130
 
131
+ gr.Markdown("# Easy Podcast (Single Speaker)")
132
+ gr.Markdown("Generate a podcast with one speaker. Choose a voice and customize details to create your perfect audio.<br>To use elevelabs voices or cloned voices, or to automate the podcast video creation with avatar contact me at aheedsajid@gmail.com<br>Support me USDT (TRC-20) (TAe7hsSVWtMEYz3G5V1UiUdYPQVqm28bKx)")
133
 
134
  with gr.Row():
135
  with gr.Column():
 
144
  value="WeePakistan",
145
  show_label=True
146
  )
 
 
147
  with gr.Column():
148
  speaker_name = gr.Textbox(
149
  label="Speaker Name",
 
151
  value="Andrew",
152
  show_label=True
153
  )
154
+
155
+ with gr.Row():
156
+ speaker_voice = gr.Dropdown(
157
+ choices=available_voices,
158
+ value=next((v for v in available_voices if "Andrew" in v), available_voices[0]),
159
+ label="Speaker Voice",
160
+ info="Select voice for the speaker"
161
+ )
162
 
163
  generate_btn = gr.Button("Generate Podcast", variant="primary")
164
 
165
+ with gr.Row():
166
+ speaker_audio = gr.Audio(label="Speaker Audio")
167
+
168
  conversation_json = gr.JSON(label="Generated Conversation")
169
 
170
  generate_btn.click(
171
  fn=generate_podcast,
172
+ inputs=[title, channel_name, speaker_name, speaker_voice],
173
+ outputs=[speaker_audio, conversation_json]
 
 
 
 
 
 
 
 
174
  )
175
 
176
  if __name__ == "__main__":
177
+ interface.launch()