|
4 | 4 |
|
5 | 5 | import threading |
6 | 6 | import os |
| 7 | +import sys |
7 | 8 |
|
8 | 9 | from datetime import datetime, timedelta |
9 | 10 | from queue import Queue |
|
29 | 30 |
|
30 | 31 | # Azure Parameters |
31 | 32 | AZURE_SPEECH_VOICE = "en-GB-OliverNeural" |
| 33 | +DEVICE_ID = None |
32 | 34 |
|
33 | 35 | # Speech Recognition Parameters |
34 | 36 | ENERGY_THRESHOLD = 1000 # Energy level for mic to detect |
|
47 | 49 | speech_key = os.environ.get("SPEECH_KEY") |
48 | 50 | service_region = os.environ.get("SPEECH_REGION") |
49 | 51 |
|
| 52 | +if openai.api_key is None or speech_key is None or service_region is None: |
| 53 | + print( |
| 54 | + "Please set the OPENAI_API_KEY, SPEECH_KEY, and SPEECH_REGION environment variables first." |
| 55 | + ) |
| 56 | + sys.exit(1) |
| 57 | + |
50 | 58 | speech_config = speechsdk.SpeechConfig(subscription=speech_key, region=service_region) |
51 | 59 | speech_config.speech_synthesis_voice_name = AZURE_SPEECH_VOICE |
52 | 60 |
|
@@ -157,10 +165,14 @@ def __init__(self, azure_speech_config): |
157 | 165 | self.do_mouth_movement = False |
158 | 166 | self._mouth_thread = threading.Thread(target=self.move_mouth, daemon=True) |
159 | 167 | self._mouth_thread.start() |
160 | | - |
| 168 | + if DEVICE_ID is None: |
| 169 | + audio_config = speechsdk.audio.AudioOutputConfig(use_default_speaker=True) |
| 170 | + else: |
| 171 | + audio_config = speechsdk.audio.AudioOutputConfig(device_name=DEVICE_ID) |
161 | 172 | self._speech_synthesizer = speechsdk.SpeechSynthesizer( |
162 | | - speech_config=azure_speech_config |
| 173 | + speech_config=azure_speech_config, audio_config=audio_config |
163 | 174 | ) |
| 175 | + |
164 | 176 | self._speech_synthesizer.synthesizing.connect(self.start_moving_mouth) |
165 | 177 | self._speech_synthesizer.synthesis_completed.connect(self.stop_moving_mouth) |
166 | 178 |
|
|
0 commit comments