Check for API Keys instead of just crash

This commit is contained in:
Melissa LeBlanc-Williams 2023-04-03 15:46:01 -07:00
parent f4742cd7c6
commit 3234a04726

View file

@ -4,6 +4,7 @@
import threading
import os
import sys
from datetime import datetime, timedelta
from queue import Queue
@ -48,6 +49,12 @@ openai.api_key = os.environ.get("OPENAI_API_KEY")
speech_key = os.environ.get("SPEECH_KEY")
service_region = os.environ.get("SPEECH_REGION")
if openai.api_key is None or speech_key is None or service_region is None:
print(
"Please set the OPENAI_API_KEY, SPEECH_KEY, and SPEECH_REGION environment variables first."
)
sys.exit(1)
speech_config = speechsdk.SpeechConfig(subscription=speech_key, region=service_region)
speech_config.speech_synthesis_voice_name = AZURE_SPEECH_VOICE