first pass at turn based conversation
This commit is contained in:
parent
d1118d375e
commit
518a0f2b53
40 changed files with 503 additions and 99 deletions
9
vocode/turn_based/output_device/base_output_device.py
Normal file
9
vocode/turn_based/output_device/base_output_device.py
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
from pydub import AudioSegment
|
||||
|
||||
|
||||
class BaseOutputDevice:
|
||||
def send_audio(self, audio: AudioSegment) -> None:
|
||||
raise NotImplementedError
|
||||
|
||||
def terminate(self):
|
||||
pass
|
||||
32
vocode/turn_based/output_device/speaker_output.py
Normal file
32
vocode/turn_based/output_device/speaker_output.py
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
import sounddevice as sd
|
||||
import numpy as np
|
||||
from pydub import AudioSegment
|
||||
|
||||
from vocode.turn_based.output_device.base_output_device import BaseOutputDevice
|
||||
|
||||
|
||||
class SpeakerOutput(BaseOutputDevice):
|
||||
DEFAULT_SAMPLING_RATE = 44100
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
device_info: dict,
|
||||
sampling_rate: int = None,
|
||||
):
|
||||
self.device_info = device_info
|
||||
self.sampling_rate = sampling_rate or int(
|
||||
self.device_info.get("default_samplerate", self.DEFAULT_SAMPLING_RATE)
|
||||
)
|
||||
self.stream = sd.OutputStream(
|
||||
channels=1,
|
||||
samplerate=self.sampling_rate,
|
||||
dtype=np.int16,
|
||||
device=int(self.device_info["index"]),
|
||||
)
|
||||
self.stream.start()
|
||||
|
||||
def send_audio(self, audio_segment: AudioSegment):
|
||||
self.stream.write(np.frombuffer(audio_segment.raw_data, dtype=np.int16))
|
||||
|
||||
def terminate(self):
|
||||
self.stream.close()
|
||||
Loading…
Add table
Add a link
Reference in a new issue