Skip to content

Commit

Permalink
azure stt: auto detect multi-languages
Browse files Browse the repository at this point in the history
  • Loading branch information
duyalei committed Sep 23, 2024
1 parent 3209160 commit 76b9bbf
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/pipecat/services/azure.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
SpeechSynthesizer,
ResultReason,
CancellationReason,
languageconfig
)
from azure.cognitiveservices.speech.audio import AudioStreamFormat, PushAudioInputStream
from azure.cognitiveservices.speech.dialog import AudioConfig
Expand Down Expand Up @@ -139,14 +140,23 @@ def __init__(
super().__init__(**kwargs)

speech_config = SpeechConfig(subscription=api_key, region=region)
speech_config.speech_recognition_language = language

stream_format = AudioStreamFormat(samples_per_second=sample_rate, channels=channels)
self._audio_stream = PushAudioInputStream(stream_format)

audio_config = AudioConfig(stream=self._audio_stream)
self._speech_recognizer = SpeechRecognizer(
speech_config=speech_config, audio_config=audio_config)
# supported languages are listed here:
# https://learn.microsoft.com/en-us/azure/ai-services/speech-service/language-support?tabs=language-identification
if isinstance(language, list):
self._speech_recognizer = SpeechRecognizer(
speech_config=speech_config,
audio_config=audio_config,
auto_detect_source_language_config=languageconfig.AutoDetectSourceLanguageConfig(
languages=language)
)
else:
self._speech_recognizer = SpeechRecognizer(speech_config=speech_config,
audio_config=audio_config,
language=language)
self._speech_recognizer.recognized.connect(self._on_handle_recognized)

async def run_stt(self, audio: bytes) -> AsyncGenerator[Frame, None]:
Expand Down

0 comments on commit 76b9bbf

Please sign in to comment.