Show HN: Open-source, native audio flip detection mannequin
This is an open supply, community-driven, native audio flip detection mannequin.
HuggingFace web page: pipecat-ai/smart-turn
Turn detection is without doubt one of the most vital capabilities of a conversational voice AI expertise stack. Turn detection means deciding when a voice agent ought to reply to human speech.
Most voice brokers as we speak use voice exercise detection (VAD) as the idea for flip detection. VAD segments audio into "speech" and "non-speech" segments. VAD cannot bear in mind the precise linguistic or acoustic content material of the speech. Humans do flip detection based mostly on grammar, tone and tempo of speech, and varied different complicated audio and semantic cues. We wish to construct a mannequin that matches human expectations extra intently than the VAD-based method can.
This is a very open mannequin (BSD 2-clause license). Anyone can use, fork, and contribute to this undertaking. This mannequin began its life as a piece in progress part of the Pipecat ecosystem. Pipecat is an open supply, vendor impartial framework for constructing voice and multimodal realtime AI brokers.
This is an preliminary proof-of-concept mannequin. It handles a small variety of widespread non-completion situations. It helps solely English. The coaching knowledge set is comparatively small.
We have experimented with various totally different architectures and approaches to coaching knowledge, and are releasing this model of the mannequin now as a result of we’re assured that efficiency might be quickly improved.
We invite you to strive it, and to contribute to mannequin improvement and experimentation.
Set up the setting.
python3.12 -m venv venv
supply venv/bin/activate
pip set up -r necessities.txt
Run a command-line utility that streams audio from the system microphone, detects phase begin/cease utilizing VAD, and sends every phase to the mannequin for a phrase endpoint prediction.
#
# It will take about 30 seconds to start out up the primary time.
#
# "Vocabulary" is proscribed. Try:
#
# - "I can not seem to, um ..."
# - "I can not seem to, um, discover the return label."
python record_and_predict.py
The present model of this mannequin is predicated on Meta AI’s Wav2Vec2-BERT spine. More on mannequin structure under.
The high-level purpose of this undertaking is to construct a state-of-the-art flip detection mannequin that’s:
- Anyone can use,
- Is simple to deploy in manufacturing,
- Is simple to fine-tune for particular utility wants.
Current limitations:
- English solely
- Relatively gradual inference
- ~150ms on GPU
- ~1500ms on CPU
- Training knowledge targeted totally on pause filler phrases on the finish of a phase.
Medium-term objectives:
- Support for a variety of languages
- Inference time <50ms on GPU and <500ms on CPU
- Much wider vary of speech nuances captured in coaching knowledge
- A very artificial coaching knowledge pipeline
- Text conditioning of the mannequin, to assist "modes" like bank card, phone quantity, and handle entry.
Wav2Vec2-BERT is a speech encoder mannequin developed as a part of Meta AI’s Seamless-M4T undertaking. It is a 580M parameter base mannequin that may leverage each acoustic and linguistic info. The base mannequin is educated on 4.5M hours of unlabeled audio knowledge masking greater than 143 languages.
To use Wav2Vec2-BERT, you usually add extra layers to the bottom mannequin after which prepare/fine-tune on an application-specific dataset.
We are at present utilizing a easy, two-layer classification head, conveniently packaged within the Hugging Face Transformers library as Wav2Vec2BertForSequenceClassification.
We have experimented with a wide range of architectures, together with the widely-used predecessor of Wav2Vec2-BERT, Wav2Vec2, and extra complicated approaches to classification. Some of us who’re engaged on the mannequin assume that the easy classification head will work properly as we scale the information set to incorporate extra complexity. Some of us have the other instinct. Time will inform! Experimenting with additions to the mannequin structure is a superb studying undertaking if you’re simply stepping into ML engineering. See "Things to do" under.
predict.py reveals move an audio pattern by way of the mannequin for classification. A small comfort operate in inference.py wraps the audio preprocessing and PyTorch inference code.
# outlined in inference.py
def predict_endpoint(audio_array):
"""
Predict whether or not an audio phase is full (flip ended) or incomplete.
Args:
audio_array: Numpy array containing audio samples at 16kHz
Returns:
Dictionary containing prediction outcomes:
- prediction: 1 for full, 0 for incomplete
- chance: Probability of completion class
"""
# Process audio
inputs = processor(
audio_array,
sampling_rate=16000,
padding="max_length",
truncation=True,
max_length=800, # Maximum size as laid out in coaching
return_attention_mask=True,
return_tensors="pt",
)
# Move inputs to gadget
inputs = {okay: v.to(gadget) for okay, v in inputs.gadgets()}
# Run inference
with torch.no_grad():
outputs = mannequin(**inputs)
logits = outputs.logits
# Get chances utilizing softmax
chances = torch.nn.practical.softmax(logits, dim=1)
completion_prob = chances[0, 1].merchandise() # Probability of sophistication 1 (Complete)
# Make prediction (1 for Complete, 0 for Incomplete)
prediction = 1 if completion_prob > 0.5 else 0
return {
"prediction": prediction,
"chance": completion_prob,
}
All coaching code is outlined in prepare.py.
You can run coaching regionally or utilizing Modal. Training runs are logged to Weights & Biases except you disable logging.
# To run a coaching job on Modal, add coaching knowledge to a Modal quantity,
# arrange the Modal setting, then run:
modal run --detach prepare.py
Currently, there are two datasets used for coaching and analysis:
- datasets/human_5_all — segmented speech recorded from human interactions
- datasets/rime_2 — artificial speech generated utilizing Rime
Four splits are created when these two datasets are loaded.
- The prepare, validate, and check units are a mixture of artificial and human knowledge
- The human eval set accommodates solely human knowledge
7 -- TRAIN --
8 Total samples: 5,694
9 Positive samples (Complete): 2,733 (48.00%)
10 Negative samples (Incomplete): 2,961 (52.00%)
11
12 -- VALIDATION --
13 Total samples: 712
14 Positive samples (Complete): 352 (49.44%)
15 Negative samples (Incomplete): 360 (50.56%)
16
17 -- TEST --
18 Total samples: 712
19 Positive samples (Complete): 339 (47.61%)
20 Negative samples (Incomplete): 373 (52.39%)
21
22 -- HUMAN_EVAL --
23 Total samples: 773
24 Positive samples (Complete): 372 (48.12%)
25 Negative samples (Incomplete): 401 (51.88%)
Our purpose for an preliminary model of this mannequin was to overfit on a non-trivial quantity of information, plus exceed a non-quantitative vibes threshold when experimenting interactively. The subsequent step is to broaden the quantity of information and transfer away from overfitting in the direction of extra generalization.
[ more notes on data coming soon ]
The base Wav2Vec2-BERT mannequin is educated on a considerable amount of multi-lingual knowledge. Supporting extra languages would require both accumulating and cleansing or synthetically producing knowledge for every language.
The present checkpoint was educated on a dataset of roughly 8,000 samples. These samples principally deal with filler phrases which might be typical indications of a pause with out utterance completion in English-language speech.
Two knowledge units are utilized in coaching: round 4,000 samples collected from human audio system, and round 4,000 artificial knowledge samples generated utilizing Rime.
The largest short-term knowledge want is to gather, categorize, and clear human knowledge samples that characterize a broader vary of speech patterns:
- inflection and pacing that signifies a "pondering" pause moderately than a accomplished speech phase
- grammatical buildings that usually happen in unfinished speech segments (however not in completed segments)
- extra particular person audio system represented
- extra areas and accents represented
The artificial knowledge samples within the datasets/rime_2 dataset solely enhance mannequin efficiency by a small margin, proper now. But one doable purpose for this undertaking is to work in the direction of a totally artificial knowledge era pipeline. The potential benefits of such a pipeline embrace the flexibility to assist extra languages extra simply, a greater flywheel for constructing extra correct variations of the mannequin, and the flexibility to quickly customise the mannequin for particular use instances.
If you’ve got experience in steering speech fashions in order that they output particular patterns (or if you wish to experiment and study), please take into account contributing artificial knowledge.
The present mannequin structure is comparatively easy, as a result of the bottom Wav2Vec2-BERT mannequin is already fairly highly effective.
However, it might be fascinating to experiment with different approaches to classification added on prime of the Wav2Vec2-BERT mannequin. This may be notably helpful if we wish to transfer away from binary classification in the direction of an method that’s extra personalized for this flip detection process.
For instance, it might be nice to supply the mannequin with extra context to situation the inference. A use case for this may be for the mannequin to "know" that the consumer is at present reciting a bank card quantity, or a cellphone quantity, or an electronic mail handle.
Adding extra context to the mannequin is an open-ended analysis problem. Some less complicated todo record gadgets embrace:
- Experimenting with freezing totally different numbers of layers throughout coaching.
- Hyperparameter tuning.
- Trying totally different sizes for the classification head or reasonably totally different classification head designs and loss capabilities.
We educated early variations of this mannequin on Google Colab. We ought to assist Colab as a coaching platform, once more! It can be nice to have quickstarts for coaching on all kinds of platforms.
We ought to alsoport the coaching code to Apple’s MLX platform. Quite a lot of us have MacBooks!
This mannequin will probably carry out properly in quantized variations. Quantized variations ought to run considerably quicker than the present float32 weights.
The PyTorch inference code isn’t notably optimized. We ought to have the ability to hand-write inference code that runs considerably quicker on each GPU and CPU, for this mannequin structure.
It can be good to port inference code to Apple’s MLX platform. This can be explicit helpful for native improvement and debugging, in addition to probably open up the potential of operating this mannequin regionally on iOS units (together with quantization).
HI-FI News
through Hacker News https://ift.tt/Zl0Rf9n
March 7, 2025 at 12:13AM
-
Product on sale
Audiophile Vinyl Records Cleaning BundleOriginal price was: €69.90.€59.90Current price is: €59.90. incl. VAT -
Product on sale
Easy Start Vinyl Records Cleaning KitOriginal price was: €69.90.€59.90Current price is: €59.90. incl. VAT -
Vinyl Records Cleaner Easy Groove Concentrate€34.95 incl. VAT -
Easy Groove Super Set€199.00 incl. VAT -
Easy Groove Enzycaster – vinyl records prewash cleaner€34.95 incl. VAT -
Easy Groove Extreme MK. II- vinyl records prewash cleaner€45.00 incl. VAT -
Vinyl Records Cleaner – Easy Groove Virgin Concentrate€35.00 incl. VAT -
Easy Groove Spray&Wipe vinyl records cleaner€34.95 incl. VAT









