feat(transcription): add language parameter for Groq Whisper STT
This commit is contained in:
@@ -25,6 +25,7 @@ class BaseChannel(ABC):
|
||||
transcription_provider: str = "groq"
|
||||
transcription_api_key: str = ""
|
||||
transcription_api_base: str = ""
|
||||
transcription_language: str = ""
|
||||
|
||||
def __init__(self, config: Any, bus: MessageBus):
|
||||
"""
|
||||
@@ -54,6 +55,7 @@ class BaseChannel(ABC):
|
||||
provider = GroqTranscriptionProvider(
|
||||
api_key=self.transcription_api_key,
|
||||
api_base=self.transcription_api_base or None,
|
||||
language=self.transcription_language or None,
|
||||
)
|
||||
return await provider.transcribe(file_path)
|
||||
except Exception as e:
|
||||
|
||||
@@ -88,6 +88,7 @@ class ChannelManager:
|
||||
channel.transcription_provider = transcription_provider
|
||||
channel.transcription_api_key = transcription_key
|
||||
channel.transcription_api_base = transcription_base
|
||||
channel.transcription_language = getattr(self.config.channels, "transcription_language", "")
|
||||
self.channels[name] = channel
|
||||
logger.info("{} channel enabled", cls.display_name)
|
||||
except Exception as e:
|
||||
|
||||
@@ -29,6 +29,7 @@ class ChannelsConfig(Base):
|
||||
send_tool_hints: bool = False # stream tool-call hints (e.g. read_file("…"))
|
||||
send_max_retries: int = Field(default=3, ge=0, le=10) # Max delivery attempts (initial send included)
|
||||
transcription_provider: str = "groq" # Voice transcription backend: "groq" or "openai"
|
||||
transcription_language: str = "" # Language code for Whisper STT (e.g. "en", "ru", "zh")
|
||||
|
||||
|
||||
class DreamConfig(Base):
|
||||
|
||||
@@ -48,9 +48,10 @@ class GroqTranscriptionProvider:
|
||||
Groq offers extremely fast transcription with a generous free tier.
|
||||
"""
|
||||
|
||||
def __init__(self, api_key: str | None = None, api_base: str | None = None):
|
||||
def __init__(self, api_key: str | None = None, api_base: str | None = None, language: str | None = None):
|
||||
self.api_key = api_key or os.environ.get("GROQ_API_KEY")
|
||||
self.api_url = api_base or os.environ.get("GROQ_BASE_URL") or "https://api.groq.com/openai/v1/audio/transcriptions"
|
||||
self.language = language
|
||||
|
||||
async def transcribe(self, file_path: str | Path) -> str:
|
||||
"""
|
||||
@@ -78,6 +79,8 @@ class GroqTranscriptionProvider:
|
||||
"file": (path.name, f),
|
||||
"model": (None, "whisper-large-v3"),
|
||||
}
|
||||
if self.language:
|
||||
files["language"] = (None, self.language)
|
||||
headers = {
|
||||
"Authorization": f"Bearer {self.api_key}",
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user