Files
livekit-agents/python/livekit-plugins/livekit-plugins-deepgram/livekit/plugins/deepgram/models.py
T

250 lines
5.9 KiB
Python

from typing import Annotated, Literal
from pydantic import BaseModel, ConfigDict, Field, TypeAdapter
DeepgramModels = Literal[
"nova-general",
"nova-phonecall",
"nova-meeting",
"nova-2-general",
"nova-2-meeting",
"nova-2-phonecall",
"nova-2-finance",
"nova-2-conversationalai",
"nova-2-voicemail",
"nova-2-video",
"nova-2-medical",
"nova-2-drivethru",
"nova-2-automotive",
"nova-2-atc",
"nova-3",
"nova-3-general",
"nova-3-medical",
"nova-3-multilingual",
"enhanced-general",
"enhanced-meeting",
"enhanced-phonecall",
"enhanced-finance",
"base",
"meeting",
"phonecall",
"finance",
"conversationalai",
"voicemail",
"video",
"whisper-tiny",
"whisper-base",
"whisper-small",
"whisper-medium",
"whisper-large",
"flux-general-en",
]
V2Models = Literal["flux-general-en", "flux-general-multi"]
# https://developers.deepgram.com/docs/models-languages-overview
DeepgramLanguages = Literal[
"zh",
"zh-CN",
"zh-TW",
"zh-HK",
"da",
"nl",
"en",
"en-US",
"en-AU",
"en-GB",
"en-NZ",
"en-IN",
"fr",
"fr-CA",
"de",
"hi",
"hi-Latn",
"id",
"it",
"ja",
"ko",
"no",
"pl",
"pt",
"pt-BR",
"ru",
"es",
"es-419",
"es-LATAM",
"sv",
"ta",
"taq",
"th",
"tr",
"uk",
"multi",
]
# https://developers.deepgram.com/docs/tts-models
TTSModels = Literal[
# Aura-2 English
"aura-2-andromeda-en",
"aura-2-apollo-en",
"aura-2-arcas-en",
"aura-2-aries-en",
"aura-2-artemis-en",
"aura-2-asteria-en",
"aura-2-atlas-en",
"aura-2-aurora-en",
"aura-2-callisto-en",
"aura-2-cetus-en",
"aura-2-chiron-en",
"aura-2-columbia-en",
"aura-2-cordelia-en",
"aura-2-crina-en",
"aura-2-draco-en",
"aura-2-electra-en",
"aura-2-eos-en",
"aura-2-harmonia-en",
"aura-2-helios-en",
"aura-2-hera-en",
"aura-2-hermes-en",
"aura-2-hyperion-en",
"aura-2-io-en",
"aura-2-iris-en",
"aura-2-janus-en",
"aura-2-juno-en",
"aura-2-jupiter-en",
"aura-2-luna-en",
"aura-2-mars-en",
"aura-2-minerva-en",
"aura-2-mira-en",
"aura-2-neptune-en",
"aura-2-odysseus-en",
"aura-2-ophiuchus-en",
"aura-2-orion-en",
"aura-2-orpheus-en",
"aura-2-phoebe-en",
"aura-2-pluto-en",
"aura-2-saturn-en",
"aura-2-selene-en",
"aura-2-theia-en",
"aura-2-titan-en",
"aura-2-triton-en",
"aura-2-vega-en",
"aura-2-venus-en",
"aura-2-zeus-en",
# Aura-1 English (legacy)
"aura-asteria-en",
"aura-luna-en",
"aura-stella-en",
"aura-athena-en",
"aura-hera-en",
"aura-orion-en",
"aura-arcas-en",
"aura-perseus-en",
"aura-angus-en",
"aura-orpheus-en",
"aura-helios-en",
"aura-zeus-en",
]
# Flux TTS voices, served on the /v2/speak endpoint.
# https://developers.deepgram.com/docs/flux-tts/overview
# Model names follow the `flux-{voice}-{language}` format; seeded with the
# documented example and kept open via `FluxTTSModels | str` so new voices
# work without a code change.
FluxTTSModels = Literal["flux-alexis-en"]
class TranscriptionWord(BaseModel):
model_config = ConfigDict(strict=True)
word: str = ""
punctuated_word: str | None = None
start: float = 0.0
end: float = 0.0
confidence: float | None = None
speaker: int | None = None
class TranscriptionAlternative(BaseModel):
model_config = ConfigDict(strict=True)
transcript: str
confidence: float
words: list[TranscriptionWord] = Field(default_factory=list[TranscriptionWord])
languages: list[str] = Field(default_factory=list[str])
class TranscriptionChannel(BaseModel):
model_config = ConfigDict(strict=True)
alternatives: list[TranscriptionAlternative] = Field(
default_factory=list[TranscriptionAlternative]
)
detected_language: str = ""
class TranscriptionMetadata(BaseModel):
model_config = ConfigDict(strict=True)
request_id: str = ""
class TranscriptionResults(BaseModel):
model_config = ConfigDict(strict=True)
channels: list[TranscriptionChannel] = Field(default_factory=list[TranscriptionChannel])
class TranscriptionResponse(BaseModel):
model_config = ConfigDict(strict=True)
type: str = ""
metadata: TranscriptionMetadata = Field(default_factory=TranscriptionMetadata)
channel: TranscriptionChannel = Field(default_factory=TranscriptionChannel)
results: TranscriptionResults = Field(default_factory=TranscriptionResults)
is_final: bool = False
speech_final: bool = False
class LiveTranscriptionResponse(BaseModel):
model_config = ConfigDict(strict=True)
type: Literal["Results"]
metadata: TranscriptionMetadata = Field(default_factory=TranscriptionMetadata)
channel: TranscriptionChannel = Field(default_factory=TranscriptionChannel)
is_final: bool = False
speech_final: bool = False
class SpeechBoundaryResponse(BaseModel):
model_config = ConfigDict(strict=True)
type: Literal["SpeechStarted", "UtteranceEnd"]
channel: list[int] = Field(default_factory=list[int])
timestamp: float | None = None
last_word_end: float | None = None
class MetadataResponse(BaseModel):
type: Literal["Metadata"]
StreamResponse = LiveTranscriptionResponse | SpeechBoundaryResponse | MetadataResponse
STREAM_RESPONSE: TypeAdapter[StreamResponse] = TypeAdapter(
Annotated[StreamResponse, Field(discriminator="type")]
)
class FluxResponse(BaseModel):
model_config = ConfigDict(strict=True)
type: str = ""
request_id: str | None = None
event: str = ""
transcript: str = ""
words: list[TranscriptionWord] = Field(default_factory=list[TranscriptionWord])
languages: list[str] = Field(default_factory=list[str])
audio_window_start: float = 0.0
audio_window_end: float = 0.0
description: str | None = None