Untitled

mail@pastecode.io avatar
unknown
python
2 years ago
439 B
1
Indexable
Never
pip install transformers
pip install pipeline
pip install sounddevice

pipe = pipeline('audio-classification') # Default model: superb/wav2vec2-base-superb-ks

import sounddevice as sd
from scipy.io.wavfile import write

fs = 16000
dur = 2

audio = sd.rec(int(dur*fs), samplerate=fs, channels=1, dtype='float64')
sd.wait()

import IPython

audio = audio.reshape((1,-1))
IPython.display.Audio(audio, rate=fs)

pipe(audio.squeeze(), top_k=3)