2024-02-15 12:27:13 +01:00
|
|
|
import moviepy.editor as mp
|
2024-02-13 14:15:27 +01:00
|
|
|
from abc import ABC, abstractmethod
|
2024-02-15 12:27:13 +01:00
|
|
|
# Assuming BaseEngine is defined elsewhere in your project
|
2024-02-13 14:15:27 +01:00
|
|
|
from ..BaseEngine import BaseEngine
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class BaseTTSEngine(BaseEngine):
|
|
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
|
def synthesize(self, text: str, path: str) -> str:
|
2024-02-14 17:49:51 +01:00
|
|
|
pass
|
2024-02-15 12:27:13 +01:00
|
|
|
|
|
|
|
|
def force_duration(self, duration: float, path: str):
|
|
|
|
|
audio_clip = mp.AudioFileClip(path)
|
|
|
|
|
|
|
|
|
|
if audio_clip.duration > duration:
|
|
|
|
|
speed_factor = audio_clip.duration / duration
|
|
|
|
|
|
|
|
|
|
new_audio = audio_clip.fx(mp.vfx.speedx, speed_factor, final_duration=duration)
|
|
|
|
|
|
|
|
|
|
new_audio.write_audiofile(path, codec='libmp3lame')
|
|
|
|
|
|
|
|
|
|
audio_clip.close()
|