koby commited on
Commit
ee2ba54
·
1 Parent(s): f882299

ogg opus download (192k)

Browse files
Files changed (1) hide show
  1. app.py +17 -2
app.py CHANGED
@@ -69,6 +69,14 @@ def flac_to_wav(flac_path, wav_path):
69
  return wav_path
70
 
71
 
 
 
 
 
 
 
 
 
72
  def _fade_out(flac_path, total_seconds, fade_dur=2.0):
73
  """Gentle fade at the very end so a forced stop never clicks. Keeps exact length."""
74
  try:
@@ -160,6 +168,12 @@ def generate(style, lyrics, cot, seed, cfg_scale, duration):
160
  _fade_out(flac_path, duration)
161
  flac_to_mp3(flac_path, mp3_path)
162
  flac_to_wav(flac_path, wav_path)
 
 
 
 
 
 
163
 
164
  words = (style or "").strip().replace("\n", " ").split()[:8]
165
  title = " ".join(words).title()[:80] if words else f"YuE2 Song {song_id[:6]}"
@@ -179,7 +193,7 @@ def generate(style, lyrics, cot, seed, cfg_scale, duration):
179
  "created_at": datetime.now(timezone.utc).isoformat(),
180
  }, song_id)
181
 
182
- return flac_path, flac_path, mp3_path, f"seed={seed} | {actual:.0f}s (asked {duration}s) | {os.path.getsize(mp3_path) // 1024}KB MP3 320kbps"
183
 
184
 
185
  with gr.Blocks(title="YuE2-3B Music") as demo:
@@ -200,8 +214,9 @@ with gr.Blocks(title="YuE2-3B Music") as demo:
200
  audio = gr.Audio(label="Play song", type="filepath")
201
  flac_file = gr.File(label="Download FLAC")
202
  mp3_file = gr.File(label="Download MP3 320kbps")
 
203
  info = gr.Textbox(label="Info")
204
- btn.click(fn=generate, inputs=[style, lyrics, cot, seed, cfg, duration], outputs=[audio, flac_file, mp3_file, info], queue=True)
205
  duration.change(fn=_dur_label, inputs=duration, outputs=duration_txt)
206
  gr.Markdown(
207
  "---\n🎶 **Community songs:** every generation is auto-shared to the "
 
69
  return wav_path
70
 
71
 
72
+ def flac_to_ogg(flac_path, ogg_path, bitrate="192k"):
73
+ subprocess.run(
74
+ ["ffmpeg", "-y", "-i", flac_path, "-c:a", "libopus", "-b:a", bitrate, ogg_path],
75
+ capture_output=True, check=True,
76
+ )
77
+ return ogg_path
78
+
79
+
80
  def _fade_out(flac_path, total_seconds, fade_dur=2.0):
81
  """Gentle fade at the very end so a forced stop never clicks. Keeps exact length."""
82
  try:
 
168
  _fade_out(flac_path, duration)
169
  flac_to_mp3(flac_path, mp3_path)
170
  flac_to_wav(flac_path, wav_path)
171
+ ogg_path = os.path.join(OUT, f"{song_id}.ogg")
172
+ try:
173
+ flac_to_ogg(flac_path, ogg_path)
174
+ except Exception as e:
175
+ print(f"[ogg] skipped: {e}")
176
+ ogg_path = None
177
 
178
  words = (style or "").strip().replace("\n", " ").split()[:8]
179
  title = " ".join(words).title()[:80] if words else f"YuE2 Song {song_id[:6]}"
 
193
  "created_at": datetime.now(timezone.utc).isoformat(),
194
  }, song_id)
195
 
196
+ return flac_path, flac_path, mp3_path, ogg_path, f"seed={seed} | {actual:.0f}s (asked {duration}s) | {os.path.getsize(mp3_path) // 1024}KB MP3 320kbps"
197
 
198
 
199
  with gr.Blocks(title="YuE2-3B Music") as demo:
 
214
  audio = gr.Audio(label="Play song", type="filepath")
215
  flac_file = gr.File(label="Download FLAC")
216
  mp3_file = gr.File(label="Download MP3 320kbps")
217
+ ogg_file = gr.File(label="Download OGG (Opus)")
218
  info = gr.Textbox(label="Info")
219
+ btn.click(fn=generate, inputs=[style, lyrics, cot, seed, cfg, duration], outputs=[audio, flac_file, mp3_file, ogg_file, info], queue=True)
220
  duration.change(fn=_dur_label, inputs=duration, outputs=duration_txt)
221
  gr.Markdown(
222
  "---\n🎶 **Community songs:** every generation is auto-shared to the "