automatic
This commit is contained in:
@@ -889,6 +889,25 @@ def create_bot(config: Config) -> discord.Client:
|
||||
f"Error reading logs: {e}", ephemeral=True
|
||||
)
|
||||
|
||||
def _wav_to_ogg(wav_path: str) -> str:
|
||||
"""Convertește WAV → OGG Opus pentru upload Discord (10x mai mic). Returnează path-ul OGG."""
|
||||
import subprocess, tempfile
|
||||
ogg_path = wav_path.replace(".wav", ".ogg")
|
||||
if not ogg_path.endswith(".ogg"):
|
||||
ogg_path = wav_path + ".ogg"
|
||||
try:
|
||||
subprocess.run(
|
||||
[
|
||||
"/home/moltbot/.local/bin/ffmpeg", "-y", "-i", wav_path,
|
||||
"-c:a", "libopus", "-b:a", "24k", "-ar", "24000", ogg_path,
|
||||
],
|
||||
capture_output=True,
|
||||
timeout=30,
|
||||
)
|
||||
return ogg_path if os.path.exists(ogg_path) else wav_path
|
||||
except Exception:
|
||||
return wav_path
|
||||
|
||||
@tree.command(name="audio", description="TTS: convertește text sau URL în voice note")
|
||||
@app_commands.describe(
|
||||
voce="Voce (M1-M5 masculin, F1-F5 feminin; default M2)",
|
||||
@@ -930,17 +949,20 @@ def create_bot(config: Config) -> discord.Client:
|
||||
result = await asyncio.to_thread(fast_dispatch, "audio", [voice, chunk])
|
||||
if result and result.startswith("__AUDIO__:"):
|
||||
wav_path = result[len("__AUDIO__:"):]
|
||||
ogg_path = await asyncio.to_thread(_wav_to_ogg, wav_path)
|
||||
try:
|
||||
filename = f"echo-audio-{i}din{total}.wav" if total > 1 else "echo-audio.wav"
|
||||
ext = "ogg" if ogg_path.endswith(".ogg") else "wav"
|
||||
filename = f"echo-audio-{i}din{total}.{ext}" if total > 1 else f"echo-audio.{ext}"
|
||||
await interaction.followup.send(
|
||||
content=f"Bucata {i}/{total}" if total > 1 else None,
|
||||
file=discord.File(wav_path, filename=filename),
|
||||
file=discord.File(ogg_path, filename=filename),
|
||||
)
|
||||
finally:
|
||||
try:
|
||||
os.unlink(wav_path)
|
||||
except OSError:
|
||||
pass
|
||||
for p in {wav_path, ogg_path}:
|
||||
try:
|
||||
os.unlink(p)
|
||||
except OSError:
|
||||
pass
|
||||
else:
|
||||
await interaction.followup.send(result or f"Eroare TTS la bucata {i}.")
|
||||
return
|
||||
@@ -957,15 +979,18 @@ def create_bot(config: Config) -> discord.Client:
|
||||
result = await asyncio.to_thread(fast_dispatch, "audio", args)
|
||||
if result and result.startswith("__AUDIO__:"):
|
||||
wav_path = result[len("__AUDIO__:"):]
|
||||
ogg_path = await asyncio.to_thread(_wav_to_ogg, wav_path)
|
||||
try:
|
||||
ext = "ogg" if ogg_path.endswith(".ogg") else "wav"
|
||||
await interaction.followup.send(
|
||||
file=discord.File(wav_path, filename="echo-audio.wav")
|
||||
file=discord.File(ogg_path, filename=f"echo-audio.{ext}")
|
||||
)
|
||||
finally:
|
||||
try:
|
||||
os.unlink(wav_path)
|
||||
except OSError:
|
||||
pass
|
||||
for p in {wav_path, ogg_path}:
|
||||
try:
|
||||
os.unlink(p)
|
||||
except OSError:
|
||||
pass
|
||||
else:
|
||||
await interaction.followup.send(result or "Eroare TTS.")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user