forked from LuciAkirami/liva
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaudio_utils.py
More file actions
22 lines (20 loc) · 737 Bytes
/
audio_utils.py
File metadata and controls
22 lines (20 loc) · 737 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
from transformers.pipelines.audio_utils import ffmpeg_microphone_live
from pydub import AudioSegment
from pydub.playback import play
import soundfile as sf
import sounddevice
class AudioUtils:
@staticmethod
def record_audio(transcriber, chunk_length_s, stream_chunk_s):
sampling_rate = transcriber.feature_extractor.sampling_rate
mic = ffmpeg_microphone_live(
sampling_rate=sampling_rate,
chunk_length_s=chunk_length_s,
stream_chunk_s=stream_chunk_s,
)
return mic
@staticmethod
def play_audio(audio_data, samplerate):
sf.write("temp_audio.wav", audio_data, samplerate)
song = AudioSegment.from_wav("temp_audio.wav")
play(song)