refactor: clean up transcription_tools after PR #262 merge
- Fix incorrect error message (only VOICE_TOOLS_OPENAI_KEY is checked, not OPENAI_API_KEY) - Remove redundant FileNotFoundError catch (exists() check above already handles this) - Consolidate openai imports to single line - Sort SUPPORTED_FORMATS in error message for deterministic output
This commit is contained in:
parent
9306a1e06a
commit
d0d9897e81
1 changed files with 3 additions and 11 deletions
|
|
@ -61,7 +61,7 @@ def transcribe_audio(file_path: str, model: Optional[str] = None) -> Dict[str, A
|
||||||
return {
|
return {
|
||||||
"success": False,
|
"success": False,
|
||||||
"transcript": "",
|
"transcript": "",
|
||||||
"error": "VOICE_TOOLS_OPENAI_KEY or OPENAI_API_KEY not set",
|
"error": "VOICE_TOOLS_OPENAI_KEY not set",
|
||||||
}
|
}
|
||||||
|
|
||||||
audio_path = Path(file_path)
|
audio_path = Path(file_path)
|
||||||
|
|
@ -86,7 +86,7 @@ def transcribe_audio(file_path: str, model: Optional[str] = None) -> Dict[str, A
|
||||||
return {
|
return {
|
||||||
"success": False,
|
"success": False,
|
||||||
"transcript": "",
|
"transcript": "",
|
||||||
"error": f"Unsupported file format: {audio_path.suffix}. Supported formats: {', '.join(SUPPORTED_FORMATS)}",
|
"error": f"Unsupported file format: {audio_path.suffix}. Supported formats: {', '.join(sorted(SUPPORTED_FORMATS))}",
|
||||||
}
|
}
|
||||||
|
|
||||||
# Validate file size
|
# Validate file size
|
||||||
|
|
@ -111,8 +111,7 @@ def transcribe_audio(file_path: str, model: Optional[str] = None) -> Dict[str, A
|
||||||
model = DEFAULT_STT_MODEL
|
model = DEFAULT_STT_MODEL
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from openai import OpenAI
|
from openai import OpenAI, APIError, APIConnectionError, APITimeoutError
|
||||||
from openai import APIError, APIConnectionError, APITimeoutError
|
|
||||||
|
|
||||||
client = OpenAI(api_key=api_key, base_url="https://api.openai.com/v1")
|
client = OpenAI(api_key=api_key, base_url="https://api.openai.com/v1")
|
||||||
|
|
||||||
|
|
@ -133,13 +132,6 @@ def transcribe_audio(file_path: str, model: Optional[str] = None) -> Dict[str, A
|
||||||
"transcript": transcript_text,
|
"transcript": transcript_text,
|
||||||
}
|
}
|
||||||
|
|
||||||
except FileNotFoundError:
|
|
||||||
logger.error("Audio file not found: %s", file_path, exc_info=True)
|
|
||||||
return {
|
|
||||||
"success": False,
|
|
||||||
"transcript": "",
|
|
||||||
"error": f"Audio file not found: {file_path}",
|
|
||||||
}
|
|
||||||
except PermissionError:
|
except PermissionError:
|
||||||
logger.error("Permission denied accessing file: %s", file_path, exc_info=True)
|
logger.error("Permission denied accessing file: %s", file_path, exc_info=True)
|
||||||
return {
|
return {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue