Spaces:
Configuration error
Configuration error
Update app_rvc.py
Browse files- app_rvc.py +27 -27
app_rvc.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import os
|
|
|
|
| 3 |
os.system("pip install -q piper-tts==1.2.0")
|
| 4 |
os.system("pip install -q -r requirements_xtts.txt")
|
| 5 |
os.system("pip install -q TTS==0.21.1 --no-deps")
|
|
@@ -127,6 +128,8 @@ directories = [
|
|
| 127 |
if not os.path.exists(directory)
|
| 128 |
]
|
| 129 |
|
|
|
|
|
|
|
| 130 |
|
| 131 |
class TTS_Info:
|
| 132 |
def __init__(self, piper_enabled, xtts_enabled):
|
|
@@ -281,7 +284,7 @@ def check_openai_api_key():
|
|
| 281 |
"translation process in Advanced settings."
|
| 282 |
)
|
| 283 |
|
| 284 |
-
def download_and_adjust_youtube_video(url, speed_factor, start_time=None, end_time=None):
|
| 285 |
# Create the 'downloaded' folder if it doesn't exist
|
| 286 |
os.makedirs("downloaded", exist_ok=True)
|
| 287 |
|
|
@@ -296,40 +299,37 @@ def download_and_adjust_youtube_video(url, speed_factor, start_time=None, end_ti
|
|
| 296 |
info = ydl.extract_info(url, download=True)
|
| 297 |
filename = ydl.prepare_filename(info)
|
| 298 |
|
| 299 |
-
#
|
| 300 |
-
|
| 301 |
-
|
| 302 |
-
|
|
|
|
| 303 |
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
|
| 308 |
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
|
| 312 |
|
| 313 |
-
|
| 314 |
-
|
| 315 |
-
|
| 316 |
-
|
| 317 |
-
|
| 318 |
|
| 319 |
-
|
| 320 |
-
|
|
|
|
|
|
|
|
|
|
| 321 |
|
| 322 |
-
# Write the adjusted video
|
| 323 |
-
try:
|
| 324 |
-
adjusted_video.write_videofile(output_filename, fps=adjusted_video.fps)
|
| 325 |
except Exception as e:
|
| 326 |
-
logger.error(f"Error
|
| 327 |
raise
|
| 328 |
|
| 329 |
-
# Close the video objects
|
| 330 |
-
video.close()
|
| 331 |
-
adjusted_video.close()
|
| 332 |
-
|
| 333 |
return output_filename
|
| 334 |
|
| 335 |
class SoniTranslate(SoniTrCache):
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import os
|
| 3 |
+
import logging
|
| 4 |
os.system("pip install -q piper-tts==1.2.0")
|
| 5 |
os.system("pip install -q -r requirements_xtts.txt")
|
| 6 |
os.system("pip install -q TTS==0.21.1 --no-deps")
|
|
|
|
| 128 |
if not os.path.exists(directory)
|
| 129 |
]
|
| 130 |
|
| 131 |
+
logging.basicConfig(level=logging.DEBUG)
|
| 132 |
+
logger = logging.getLogger(__name__)
|
| 133 |
|
| 134 |
class TTS_Info:
|
| 135 |
def __init__(self, piper_enabled, xtts_enabled):
|
|
|
|
| 284 |
"translation process in Advanced settings."
|
| 285 |
)
|
| 286 |
|
| 287 |
+
def download_and_adjust_youtube_video(url: str, speed_factor: float, start_time: float = None, end_time: float = None) -> str:
|
| 288 |
# Create the 'downloaded' folder if it doesn't exist
|
| 289 |
os.makedirs("downloaded", exist_ok=True)
|
| 290 |
|
|
|
|
| 299 |
info = ydl.extract_info(url, download=True)
|
| 300 |
filename = ydl.prepare_filename(info)
|
| 301 |
|
| 302 |
+
# Process the video
|
| 303 |
+
try:
|
| 304 |
+
with VideoFileClip(filename) as video:
|
| 305 |
+
logger.debug(f"Original video FPS: {video.fps}")
|
| 306 |
+
logger.debug(f"Original video duration: {video.duration}")
|
| 307 |
|
| 308 |
+
# Set a default fps if it's None
|
| 309 |
+
if video.fps is None:
|
| 310 |
+
video = video.set_fps(30.0)
|
| 311 |
+
logger.warning(f"Original video FPS is None. Setting to default: {video.fps}")
|
| 312 |
|
| 313 |
+
# Trim the video if start_time and end_time are provided
|
| 314 |
+
if start_time is not None and end_time is not None:
|
| 315 |
+
video = video.subclip(start_time, end_time)
|
| 316 |
|
| 317 |
+
# Adjust speed
|
| 318 |
+
adjusted_video = video.speedx(speed_factor)
|
| 319 |
+
adjusted_video = adjusted_video.set_fps(video.fps) # Ensure the adjusted video has the same fps
|
| 320 |
+
logger.debug(f"Adjusted video FPS: {adjusted_video.fps}")
|
| 321 |
+
logger.debug(f"Adjusted video duration: {adjusted_video.duration}")
|
| 322 |
|
| 323 |
+
# Generate output filename
|
| 324 |
+
output_filename = f"downloaded/{os.path.splitext(os.path.basename(filename))[0]}_speed{speed_factor}.mp4"
|
| 325 |
+
|
| 326 |
+
# Write the adjusted video
|
| 327 |
+
adjusted_video.write_videofile(output_filename, fps=adjusted_video.fps)
|
| 328 |
|
|
|
|
|
|
|
|
|
|
| 329 |
except Exception as e:
|
| 330 |
+
logger.error(f"Error processing video file: {str(e)}")
|
| 331 |
raise
|
| 332 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 333 |
return output_filename
|
| 334 |
|
| 335 |
class SoniTranslate(SoniTrCache):
|