first pass at turn based conversation
This commit is contained in:
parent
d1118d375e
commit
518a0f2b53
40 changed files with 503 additions and 99 deletions
13
vocode/streaming/output_device/base_output_device.py
Normal file
13
vocode/streaming/output_device/base_output_device.py
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
from vocode.streaming.models.audio_encoding import AudioEncoding
|
||||
|
||||
|
||||
class BaseOutputDevice:
|
||||
def __init__(self, sampling_rate: int, audio_encoding: AudioEncoding):
|
||||
self.sampling_rate = sampling_rate
|
||||
self.audio_encoding = audio_encoding
|
||||
|
||||
async def send_async(self, chunk):
|
||||
raise NotImplemented
|
||||
|
||||
async def maybe_send_mark_async(self, message):
|
||||
pass
|
||||
34
vocode/streaming/output_device/speaker_output.py
Normal file
34
vocode/streaming/output_device/speaker_output.py
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
import sounddevice as sd
|
||||
import numpy as np
|
||||
|
||||
from .base_output_device import BaseOutputDevice
|
||||
from vocode.streaming.models.audio_encoding import AudioEncoding
|
||||
|
||||
|
||||
class SpeakerOutput(BaseOutputDevice):
|
||||
DEFAULT_SAMPLING_RATE = 44100
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
device_info: dict,
|
||||
sampling_rate: int = None,
|
||||
audio_encoding: AudioEncoding = AudioEncoding.LINEAR16,
|
||||
):
|
||||
self.device_info = device_info
|
||||
sampling_rate = sampling_rate or int(
|
||||
self.device_info.get("default_samplerate", self.DEFAULT_SAMPLING_RATE)
|
||||
)
|
||||
super().__init__(sampling_rate, audio_encoding)
|
||||
self.stream = sd.OutputStream(
|
||||
channels=1,
|
||||
samplerate=self.sampling_rate,
|
||||
dtype=np.int16,
|
||||
device=int(self.device_info["index"]),
|
||||
)
|
||||
self.stream.start()
|
||||
|
||||
async def send_async(self, chunk):
|
||||
self.stream.write(np.frombuffer(chunk, dtype=np.int16))
|
||||
|
||||
def terminate(self):
|
||||
self.stream.close()
|
||||
7
vocode/streaming/output_device/telephone_output.py
Normal file
7
vocode/streaming/output_device/telephone_output.py
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
from .base_output_device import BaseOutputDevice
|
||||
from vocode.streaming.models.audio_encoding import AudioEncoding
|
||||
|
||||
|
||||
class TelephoneOutput(BaseOutputDevice):
|
||||
def __init__(self):
|
||||
super().__init__(sampling_rate=8000, audio_encoding=AudioEncoding.MULAW)
|
||||
Loading…
Add table
Add a link
Reference in a new issue