-
Notifications
You must be signed in to change notification settings - Fork 564
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
silero: fix vad padding & choppy audio (#631)
- Loading branch information
1 parent
6f534ae
commit 7b611cd
Showing
7 changed files
with
206 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"livekit-agents": patch | ||
"livekit-plugins-silero": patch | ||
--- | ||
|
||
silero: fix vad padding & static audio |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
**/test_vad*.wav |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
from livekit.agents import vad | ||
from livekit.plugins import silero | ||
|
||
from . import utils | ||
|
||
VAD = silero.VAD.load( | ||
min_speech_duration=0.5, min_silence_duration=0.5, padding_duration=1.0 | ||
) | ||
|
||
|
||
async def test_chunks_vad() -> None: | ||
frames, transcript = utils.make_test_audio(chunk_duration_ms=10) | ||
assert len(frames) > 1, "frames aren't chunked" | ||
|
||
stream = VAD.stream() | ||
|
||
for frame in frames: | ||
stream.push_frame(frame) | ||
|
||
stream.end_input() | ||
|
||
start_of_speech_i = 0 | ||
end_of_speech_i = 0 | ||
async for ev in stream: | ||
if ev.type == vad.VADEventType.START_OF_SPEECH: | ||
with open( | ||
f"test_vad.start_of_speech_frames_{start_of_speech_i}.wav", "wb" | ||
) as f: | ||
f.write(utils.make_wav_file(ev.frames)) | ||
|
||
start_of_speech_i += 1 | ||
|
||
if ev.type == vad.VADEventType.END_OF_SPEECH: | ||
with open( | ||
f"test_vad.end_of_speech_frames_{end_of_speech_i}.wav", "wb" | ||
) as f: | ||
f.write(utils.make_wav_file(ev.frames)) | ||
|
||
end_of_speech_i += 1 | ||
|
||
assert start_of_speech_i > 0, "no start of speech detected" | ||
assert start_of_speech_i == end_of_speech_i, "start and end of speech mismatch" | ||
|
||
|
||
async def test_file_vad(): | ||
frames, transcript = utils.make_test_audio() | ||
assert len(frames) == 1, "one frame should be the whole audio" | ||
|
||
stream = VAD.stream() | ||
|
||
for frame in frames: | ||
stream.push_frame(frame) | ||
|
||
stream.end_input() | ||
|
||
start_of_speech_i = 0 | ||
end_of_speech_i = 0 | ||
async for ev in stream: | ||
if ev.type == vad.VADEventType.START_OF_SPEECH: | ||
start_of_speech_i += 1 | ||
|
||
if ev.type == vad.VADEventType.END_OF_SPEECH: | ||
end_of_speech_i += 1 | ||
|
||
assert start_of_speech_i > 0, "no start of speech detected" | ||
assert start_of_speech_i == end_of_speech_i, "start and end of speech mismatch" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters