Spaces:
Sleeping
Sleeping
Audio and text edit
Browse files- audio_gen.py +27 -4
audio_gen.py
CHANGED
|
@@ -16,9 +16,7 @@ import subprocess
|
|
| 16 |
from pathlib import Path
|
| 17 |
import urllib.parse
|
| 18 |
from io import BytesIO
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
|
| 23 |
def generate_audio(text, voice_model, audio_model="deepgram"):
|
| 24 |
"""
|
|
@@ -78,4 +76,29 @@ def get_audio_duration(audio_file):
|
|
| 78 |
return 5.0
|
| 79 |
return float(result.stdout.strip())
|
| 80 |
except Exception:
|
| 81 |
-
return 5.0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
from pathlib import Path
|
| 17 |
import urllib.parse
|
| 18 |
from io import BytesIO
|
| 19 |
+
from PIL import Image
|
|
|
|
|
|
|
| 20 |
|
| 21 |
def generate_audio(text, voice_model, audio_model="deepgram"):
|
| 22 |
"""
|
|
|
|
| 76 |
return 5.0
|
| 77 |
return float(result.stdout.strip())
|
| 78 |
except Exception:
|
| 79 |
+
return 5.0
|
| 80 |
+
|
| 81 |
+
#edit text and audio
|
| 82 |
+
|
| 83 |
+
def edit_section_text(original_text: str, new_text: str, voice_model: str, audio_model: str):
|
| 84 |
+
"""
|
| 85 |
+
Takes the original text, replaces it with new_text, re-generates the audio,
|
| 86 |
+
and returns (updated_text, new_audio_path).
|
| 87 |
+
We'll assume you already have a 'generate_audio' function in this same file
|
| 88 |
+
that can produce audio from text.
|
| 89 |
+
"""
|
| 90 |
+
from audio_gen import generate_audio # or wherever your existing TTS function is
|
| 91 |
+
|
| 92 |
+
try:
|
| 93 |
+
# 1) The new text is just new_text
|
| 94 |
+
updated_text = new_text.strip()
|
| 95 |
+
if not updated_text:
|
| 96 |
+
return None, None
|
| 97 |
+
|
| 98 |
+
# 2) Re-generate the audio for the new text
|
| 99 |
+
audio_file_path = generate_audio(updated_text, voice_model, audio_model=audio_model)
|
| 100 |
+
return updated_text, audio_file_path
|
| 101 |
+
|
| 102 |
+
except Exception as e:
|
| 103 |
+
logging.error(f"Error editing section text/audio: {e}")
|
| 104 |
+
return None, None
|