From e2888ea7398ae7cad78adab280db25e2131f5e2c Mon Sep 17 00:00:00 2001 From: rjheeta Date: Thu, 13 Jun 2024 12:05:26 -0400 Subject: [PATCH] add ability to choose model file --- vocode/streaming/models/synthesizer.py | 2 +- vocode/streaming/synthesizer/orca_synthesizer.py | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/vocode/streaming/models/synthesizer.py b/vocode/streaming/models/synthesizer.py index 0ac7a721a..eba44ca9e 100644 --- a/vocode/streaming/models/synthesizer.py +++ b/vocode/streaming/models/synthesizer.py @@ -246,4 +246,4 @@ class CartesiaSynthesizerConfig(SynthesizerConfig, type=SynthesizerType.CARTESIA class OrcaSynthesizerConfig(SynthesizerConfig, type=SynthesizerType.ORCA.value): # type: ignore api_key: Optional[str] = None speech_rate: Optional[float] = None - model_file = DEFAULT_ORCA_MODEL + model_file: str = DEFAULT_ORCA_MODEL diff --git a/vocode/streaming/synthesizer/orca_synthesizer.py b/vocode/streaming/synthesizer/orca_synthesizer.py index 09d78ef83..bf0c074ef 100644 --- a/vocode/streaming/synthesizer/orca_synthesizer.py +++ b/vocode/streaming/synthesizer/orca_synthesizer.py @@ -1,4 +1,5 @@ import io +import os import wave import hashlib import struct @@ -34,7 +35,16 @@ def __init__( if synthesizer_config.speech_rate and not (0.7 <= synthesizer_config.speech_rate <= 1.3): raise ValueError("Speech rate must be between 0.7 and 1.3 inclusive") - self.orca = self.orca_lib.create(access_key=self.api_key) + if synthesizer_config.model_file: + # By default, model files are stored in the same directory as the Orca library + self.model_path = os.path.join( + os.path.dirname(self.orca_lib.default_model_path()), + synthesizer_config.model_file + ) + else: + self.model_path = None + + self.orca = self.orca_lib.create(access_key=self.api_key, model_path=self.model_path) self.speech_rate = synthesizer_config.speech_rate self.sample_rate = SamplingRate.RATE_22050.value # The only rate supported self.output_format = "pcm" # The only format supported