refactor: streamline API key retrieval in transcription and TTS tools
- Removed fallback to OPENAI_API_KEY in favor of exclusively using VOICE_TOOLS_OPENAI_KEY for improved clarity and consistency. - Updated environment variable checks to ensure only VOICE_TOOLS_OPENAI_KEY is considered, enhancing error handling and messaging.
This commit is contained in:
parent
715825eac3
commit
a5ea272936
2 changed files with 4 additions and 7 deletions
|
|
@ -50,10 +50,7 @@ def transcribe_audio(file_path: str, model: Optional[str] = None) -> dict:
|
||||||
- "transcript" (str): The transcribed text (empty on failure)
|
- "transcript" (str): The transcribed text (empty on failure)
|
||||||
- "error" (str, optional): Error message if success is False
|
- "error" (str, optional): Error message if success is False
|
||||||
"""
|
"""
|
||||||
# Use VOICE_TOOLS_OPENAI_KEY to avoid interference with the OpenAI SDK's
|
api_key = os.getenv("VOICE_TOOLS_OPENAI_KEY")
|
||||||
# auto-detection of OPENAI_API_KEY (which would break OpenRouter calls).
|
|
||||||
# Falls back to OPENAI_API_KEY for backward compatibility.
|
|
||||||
api_key = os.getenv("VOICE_TOOLS_OPENAI_KEY") or os.getenv("OPENAI_API_KEY")
|
|
||||||
if not api_key:
|
if not api_key:
|
||||||
return {
|
return {
|
||||||
"success": False,
|
"success": False,
|
||||||
|
|
|
||||||
|
|
@ -210,7 +210,7 @@ def _generate_openai_tts(text: str, output_path: str, tts_config: Dict[str, Any]
|
||||||
Returns:
|
Returns:
|
||||||
Path to the saved audio file.
|
Path to the saved audio file.
|
||||||
"""
|
"""
|
||||||
api_key = os.getenv("VOICE_TOOLS_OPENAI_KEY") or os.getenv("OPENAI_API_KEY", "")
|
api_key = os.getenv("VOICE_TOOLS_OPENAI_KEY", "")
|
||||||
if not api_key:
|
if not api_key:
|
||||||
raise ValueError("VOICE_TOOLS_OPENAI_KEY not set. Get one at https://platform.openai.com/api-keys")
|
raise ValueError("VOICE_TOOLS_OPENAI_KEY not set. Get one at https://platform.openai.com/api-keys")
|
||||||
|
|
||||||
|
|
@ -392,7 +392,7 @@ def check_tts_requirements() -> bool:
|
||||||
return True
|
return True
|
||||||
if _HAS_ELEVENLABS and os.getenv("ELEVENLABS_API_KEY"):
|
if _HAS_ELEVENLABS and os.getenv("ELEVENLABS_API_KEY"):
|
||||||
return True
|
return True
|
||||||
if _HAS_OPENAI and (os.getenv("VOICE_TOOLS_OPENAI_KEY") or os.getenv("OPENAI_API_KEY")):
|
if _HAS_OPENAI and os.getenv("VOICE_TOOLS_OPENAI_KEY"):
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
@ -409,7 +409,7 @@ if __name__ == "__main__":
|
||||||
print(f" ElevenLabs: {'✅ installed' if _HAS_ELEVENLABS else '❌ not installed (pip install elevenlabs)'}")
|
print(f" ElevenLabs: {'✅ installed' if _HAS_ELEVENLABS else '❌ not installed (pip install elevenlabs)'}")
|
||||||
print(f" API Key: {'✅ set' if os.getenv('ELEVENLABS_API_KEY') else '❌ not set'}")
|
print(f" API Key: {'✅ set' if os.getenv('ELEVENLABS_API_KEY') else '❌ not set'}")
|
||||||
print(f" OpenAI: {'✅ installed' if _HAS_OPENAI else '❌ not installed'}")
|
print(f" OpenAI: {'✅ installed' if _HAS_OPENAI else '❌ not installed'}")
|
||||||
print(f" API Key: {'✅ set' if (os.getenv('VOICE_TOOLS_OPENAI_KEY') or os.getenv('OPENAI_API_KEY')) else '❌ not set'}")
|
print(f" API Key: {'✅ set' if os.getenv('VOICE_TOOLS_OPENAI_KEY') else '❌ not set (VOICE_TOOLS_OPENAI_KEY)'}")
|
||||||
print(f" ffmpeg: {'✅ found' if _has_ffmpeg() else '❌ not found (needed for Telegram Opus)'}")
|
print(f" ffmpeg: {'✅ found' if _has_ffmpeg() else '❌ not found (needed for Telegram Opus)'}")
|
||||||
print(f"\n Output dir: {DEFAULT_OUTPUT_DIR}")
|
print(f"\n Output dir: {DEFAULT_OUTPUT_DIR}")
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue