mirror of
https://github.com/HKUDS/nanobot.git
synced 2026-08-06 17:38:35 +00:00
feat(transcription): add language parameter for Groq Whisper STT
This commit is contained in:
parent
c51b653154
commit
1835f94d8e
@ -25,6 +25,7 @@ class BaseChannel(ABC):
|
|||||||
transcription_provider: str = "groq"
|
transcription_provider: str = "groq"
|
||||||
transcription_api_key: str = ""
|
transcription_api_key: str = ""
|
||||||
transcription_api_base: str = ""
|
transcription_api_base: str = ""
|
||||||
|
transcription_language: str = ""
|
||||||
|
|
||||||
def __init__(self, config: Any, bus: MessageBus):
|
def __init__(self, config: Any, bus: MessageBus):
|
||||||
"""
|
"""
|
||||||
@ -54,6 +55,7 @@ class BaseChannel(ABC):
|
|||||||
provider = GroqTranscriptionProvider(
|
provider = GroqTranscriptionProvider(
|
||||||
api_key=self.transcription_api_key,
|
api_key=self.transcription_api_key,
|
||||||
api_base=self.transcription_api_base or None,
|
api_base=self.transcription_api_base or None,
|
||||||
|
language=self.transcription_language or None,
|
||||||
)
|
)
|
||||||
return await provider.transcribe(file_path)
|
return await provider.transcribe(file_path)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
@ -88,6 +88,7 @@ class ChannelManager:
|
|||||||
channel.transcription_provider = transcription_provider
|
channel.transcription_provider = transcription_provider
|
||||||
channel.transcription_api_key = transcription_key
|
channel.transcription_api_key = transcription_key
|
||||||
channel.transcription_api_base = transcription_base
|
channel.transcription_api_base = transcription_base
|
||||||
|
channel.transcription_language = getattr(self.config.channels, "transcription_language", "")
|
||||||
self.channels[name] = channel
|
self.channels[name] = channel
|
||||||
logger.info("{} channel enabled", cls.display_name)
|
logger.info("{} channel enabled", cls.display_name)
|
||||||
except Exception as e:
|
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_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)
|
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_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):
|
class DreamConfig(Base):
|
||||||
|
|||||||
@ -48,9 +48,10 @@ class GroqTranscriptionProvider:
|
|||||||
Groq offers extremely fast transcription with a generous free tier.
|
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_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.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:
|
async def transcribe(self, file_path: str | Path) -> str:
|
||||||
"""
|
"""
|
||||||
@ -78,6 +79,8 @@ class GroqTranscriptionProvider:
|
|||||||
"file": (path.name, f),
|
"file": (path.name, f),
|
||||||
"model": (None, "whisper-large-v3"),
|
"model": (None, "whisper-large-v3"),
|
||||||
}
|
}
|
||||||
|
if self.language:
|
||||||
|
files["language"] = (None, self.language)
|
||||||
headers = {
|
headers = {
|
||||||
"Authorization": f"Bearer {self.api_key}",
|
"Authorization": f"Bearer {self.api_key}",
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user