Can it detect laugh in audio provide timestamps?? #804
-
|
I'm looking for a solution which can detect laugh from audio and provide the timestamps for it. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
Yes for clip-level detection, but not as a native event-level timestamp.
from funasr import AutoModel
model = AutoModel(
model="iic/SenseVoiceSmall",
trust_remote_code=True,
device="cuda:0", # use "cpu" if needed
)
result = model.generate(
input="audio.wav",
language="auto",
use_itn=False,
output_timestamp=True,
)[0]
print(result["text"])
print("laughter detected:", "<|Laughter|>" in result["text"])
print(result.get("words"), result.get("timestamp"))The important limitation is that For approximate laughter locations in a long recording, run SenseVoice on overlapping windows of the raw audio and keep the windows that contain import numpy as np
import soundfile as sf
def laughter_windows(path, window_seconds=2.0, hop_seconds=0.5):
audio, sample_rate = sf.read(path, dtype="float32")
if audio.ndim == 2:
audio = audio.mean(axis=1)
original_samples = len(audio)
window = round(window_seconds * sample_rate)
hop = round(hop_seconds * sample_rate)
if original_samples < window:
audio = np.pad(audio, (0, window - original_samples))
last_start = len(audio) - window
starts = list(range(0, last_start + 1, hop))
if starts[-1] != last_start:
starts.append(last_start)
duration = original_samples / sample_rate
hits = []
for start in starts:
raw_text = model.generate(
input=audio[start : start + window],
fs=sample_rate,
language="auto",
use_itn=False,
)[0]["text"]
if "<|Laughter|>" in raw_text:
hits.append(
{
"start": start / sample_rate,
"end": min((start + window) / sample_rate, duration),
}
)
return hits
print(laughter_windows("audio.wav"))These are window-level, approximate intervals rather than exact event boundaries. In production, merge overlapping hits and usually require two consecutive positive windows to reduce false positives. Tune the window/hop on audio from your own domain; detection quality varies with recording conditions. |
Beta Was this translation helpful? Give feedback.
Yes for clip-level detection, but not as a native event-level timestamp.
SenseVoiceSmallcan emit the raw event tag<|Laughter|>. Checkresult["text"]before callingrich_transcription_postprocess, because the postprocessor turns that tag into an emoji. For example:The important li…