Skip to content

Commit

Permalink
Added return type to tts client synthsize method
Browse files Browse the repository at this point in the history
  • Loading branch information
mjbverbio committed May 15, 2024
1 parent 78e370b commit 75cebfd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
10 changes: 5 additions & 5 deletions cli-client/helpers/tts_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,16 @@ def _compose_synthesis_request(self, text: str, voice: str, audio_format: str, s

return message

def _save_audio_result(self, audio_samples: bytes):
def save_audio_result(self, audio_samples: bytes):
audio_exporter = AudioExporter(self._audio_sample_rate)
audio_exporter.save_audio(self._audio_format, audio_samples, self._audio_file)
logging.info("Stored synthesis audio at -%s-", self._audio_file)

def synthesize(self):
def synthesize(self) -> bytes:
logging.info("Sending synthesis request for voice: -%s-, sampling_rate: %i and text: -%s-", self._voice, self._audio_sample_rate, self._text)
selected_audio_format = AudioExporter.SUPPORTED_FORMATS[self._audio_format]

metadata = None if self._secure_channel else [('authorization', "Bearer " + self._token)]
logging.error("Audio sampling rate: %s", self._audio_sample_rate)
response, call = self._stub.SynthesizeSpeech.with_call(
self._compose_synthesis_request(
text=self._text,
Expand All @@ -61,7 +60,8 @@ def synthesize(self):

logging.info("Synthesis response [status=%s]", str(call.code()))
logging.info("Received response with %s bytes of audio data", len(response.audio_samples))
self._save_audio_result(response.audio_samples)

return response.audio_samples

def _close_stream_by_inactivity(self):
logging.info("Stream inactivity detected, closing stream...")
Expand Down Expand Up @@ -89,7 +89,7 @@ def _response_watcher(self, response_iterator):
self._inactivity_timer.cancel()
self._start_inactivity_timer(self._inactivity_timer_timeout)

self._save_audio_result(audio)
self.save_audio_result(audio)

except Exception as e:
logging.error("Error running response watcher: %s", str(e))
Expand Down
3 changes: 2 additions & 1 deletion cli-client/synthesizer_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ def process_synthesis(executor: ThreadPoolExecutor, channel: grpc.Channel, optio
stub = verbio_speech_center_synthesizer_pb2_grpc.TextToSpeechStub(channel)
client = TTSClient(executor, stub, options, access_token)
if options.text:
client.synthesize()
audio_samples = client.synthesize()
client.save_audio_result(audio_samples)
elif options.text_file:
client.send_text()
client.wait_for_response()
Expand Down

0 comments on commit 75cebfd

Please sign in to comment.