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 24, 2024
1 parent ee31d4f commit 867ce87
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/pipecat/services/azure.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
SpeechSynthesizer,
ResultReason,
CancellationReason,
languageconfig,
)
from azure.cognitiveservices.speech.audio import AudioStreamFormat, PushAudioInputStream
from azure.cognitiveservices.speech.dialog import AudioConfig
Expand Down Expand Up @@ -142,15 +143,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 867ce87

Please sign in to comment.