Skip to content

Make videos on the computer you already own. FreeVideo runs MiniMax H3 in as little as 8 GB of VRAM and 16 GB of RAM, and adapts its acceleration path to your hardware.

Voice references: measure speech in the first six seconds and report it on upload

Bowen Xue6bce493249b5
diff --git a/freevideo_engine/agent/comfy.py b/freevideo_engine/agent/comfy.py
index b27f631..fe25b2f 100644
--- a/freevideo_engine/agent/comfy.py
+++ b/freevideo_engine/agent/comfy.py
@@ -60,6 +60,15 @@ class ComfyPort:
def output_relative(self, path):
return Path(path).resolve().relative_to(self.output_root).as_posix()
+ def voice_window(self, path, seconds):
+ """Speech in the first seconds of an uploaded sound, or None without the speech model."""
+ from ..comfy_bridge import installation
+ from ..image_gen import image_pack
+ from ..speech import MODEL_FILE
+ from ..voice_window import inspect
+ model = image_pack.base(installation()[1]['model_root']) / MODEL_FILE
+ return inspect(path, seconds, model, self.output_root / 'FreeVideo' / '.editor' / 'speech')
+
def library_video(self, identity):
from ..comfy_library import _video, _report
try:
diff --git a/freevideo_engine/agent/routes.py b/freevideo_engine/agent/routes.py
index 7ef65d9..1df729c 100644
--- a/freevideo_engine/agent/routes.py
+++ b/freevideo_engine/agent/routes.py
@@ -1889,6 +1889,13 @@ def register():
os.replace(target, out)
info['name'] = identity + suffix
info['original_name'] = name
+ if info['kind'] in ('audio', 'video') and info.get('has_audio', info['kind'] == 'audio'):
+ try:
+ voice = await asyncio.to_thread(port.voice_window, out, info['seconds'])
+ except Exception: # noqa: BLE001 - the check is advice; an upload never fails for it
+ voice = None
+ if voice is not None:
+ info['voice'] = voice
return reply(dict(**assets.view(relative), **info), 201)
@routes.get(PREFIX + '/media/{kind}/{file:.+}/file')
diff --git a/freevideo_engine/agent/schema.py b/freevideo_engine/agent/schema.py
index 5318d9f..1adc468 100644
--- a/freevideo_engine/agent/schema.py
+++ b/freevideo_engine/agent/schema.py
@@ -169,6 +169,7 @@ def common():
def generation_media(*, local=False, enhance=False):
return obj({'first': nullable(media(True, local=local)), 'last': nullable(media(True, local=local)),
'references': nullable(array(media(enhance, local=local, early=not enhance), high=8 if enhance else 32))},
+ description='A first or last frame request does not take a voice reference.',
allOf=[{'if': {'required': ['references'], 'properties': {'references': {'type': 'array', 'minItems': 1}}},
'then': {'properties': {'first': {'type': 'null'}, 'last': {'type': 'null'}}}}])
diff --git a/freevideo_engine/voice_window.py b/freevideo_engine/voice_window.py
new file mode 100644
index 0000000..7eaa8b4
--- /dev/null
+++ b/freevideo_engine/voice_window.py
@@ -0,0 +1,36 @@
+"""How much of a voice reference's first seconds is speech.
+
+The engine reads the first WINDOW seconds of a reference sound. A window with little speech, or one that opens with
+music, gives a weak voice, so the caller can ask for another clip before spending a generation on it.
+"""
+from __future__ import annotations
+
+WINDOW = 6.
+MIN_SPEECH = 4.
+
+
+def measure(spans, duration, window=WINDOW):
+ """Speech seconds inside [0, window] from VAD spans, and when speech first starts (None without speech)."""
+ end = min(window, duration)
+ speech = sum(max(0., min(b, end) - max(a, 0.)) for a, b in spans)
+ first = next((max(a, 0.) for a, b in spans if b > 0 and a < end), None)
+ return round(speech, 2), None if first is None else round(first, 2), round(end, 2)
+
+
+def check(spans, duration):
+ """{'window', 'speech_seconds', 'first_speech', 'usable', 'reason'}; reason is None when usable."""
+ speech, first, window = measure(spans, duration)
+ need = min(MIN_SPEECH, window)
+ # A clip that opens with music has the same effect as a sparse one: the window holds too little speech.
+ reason = 'too_little_speech' if speech < need else None
+ return dict(window=window, speech_seconds=speech, first_speech=first, usable=reason is None, reason=reason)
+
+
+def inspect(path, duration, model_path, cache):
+ """check() for a sound or video file, or None when the speech model is not installed or the file cannot be read."""
+ from .speech import SpeechError, speech_spans
+ try:
+ spans = speech_spans(path, model_path, cache)
+ return check(spans, duration)
+ except SpeechError:
+ return None