-
Notifications
You must be signed in to change notification settings - Fork 493
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adds back streamingconversation test
- Loading branch information
Showing
5 changed files
with
115 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import wave | ||
from io import BytesIO | ||
|
||
from vocode.streaming.models.message import BaseMessage | ||
from vocode.streaming.models.synthesizer import SynthesizerConfig | ||
from vocode.streaming.synthesizer.base_synthesizer import BaseSynthesizer, SynthesisResult | ||
|
||
|
||
def create_fake_audio(message: str, synthesizer_config: SynthesizerConfig): | ||
file = BytesIO() | ||
with wave.open(file, "wb") as wave_file: | ||
wave_file.setnchannels(1) | ||
wave_file.setsampwidth(2) | ||
wave_file.setframerate(synthesizer_config.sampling_rate) | ||
wave_file.writeframes(message.encode()) | ||
file.seek(0) | ||
return file | ||
|
||
|
||
class TestSynthesizerConfig(SynthesizerConfig, type="synthesizer_test"): | ||
__test__ = False | ||
|
||
|
||
class TestSynthesizer(BaseSynthesizer[TestSynthesizerConfig]): | ||
"""Accepts text and creates a SynthesisResult containing audio data which is the same as the text as bytes.""" | ||
|
||
__test__ = False | ||
|
||
def __init__(self, synthesizer_config: SynthesizerConfig): | ||
super().__init__(synthesizer_config) | ||
|
||
async def create_speech_uncached( | ||
self, | ||
message: BaseMessage, | ||
chunk_size: int, | ||
is_first_text_chunk: bool = False, | ||
is_sole_text_chunk: bool = False, | ||
) -> SynthesisResult: | ||
return self.create_synthesis_result_from_wav( | ||
synthesizer_config=self.synthesizer_config, | ||
message=message, | ||
chunk_size=chunk_size, | ||
file=create_fake_audio( | ||
message=message.text, synthesizer_config=self.synthesizer_config | ||
), | ||
) | ||
|
||
@classmethod | ||
def get_voice_identifier(cls, synthesizer_config: TestSynthesizerConfig) -> str: | ||
return "test_voice" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import asyncio | ||
|
||
from vocode.streaming.models.transcriber import TranscriberConfig | ||
from vocode.streaming.transcriber.base_transcriber import BaseAsyncTranscriber, Transcription | ||
|
||
|
||
class TestTranscriberConfig(TranscriberConfig, type="transcriber_test"): | ||
__test__ = False | ||
|
||
|
||
class TestAsyncTranscriber(BaseAsyncTranscriber[TestTranscriberConfig]): | ||
"""Accepts fake audio chunks and sends out transcriptions which are the same as the audio chunks.""" | ||
|
||
__test__ = False | ||
|
||
async def _run_loop(self): | ||
while True: | ||
try: | ||
audio_chunk = await self.input_queue.get() | ||
self.produce_nonblocking( | ||
Transcription(message=audio_chunk.decode("utf-8"), confidence=1, is_final=True) | ||
) | ||
except asyncio.CancelledError: | ||
return |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters