-
Notifications
You must be signed in to change notification settings - Fork 3.2k
feat(deepgram): support diarize_model option and V2 diarization #6104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -68,6 +68,7 @@ class STTOptions: | |||||||||||||||||
| keyterm: str | Sequence[str] | ||||||||||||||||||
| profanity_filter: bool | ||||||||||||||||||
| redact: str | list[str] | ||||||||||||||||||
| diarize_model: str | ||||||||||||||||||
| endpoint_url: str | ||||||||||||||||||
| vad_events: bool = True | ||||||||||||||||||
| numerals: bool = False | ||||||||||||||||||
|
|
@@ -89,6 +90,7 @@ def __init__( | |||||||||||||||||
| no_delay: bool = True, | ||||||||||||||||||
| endpointing_ms: int = 25, | ||||||||||||||||||
| enable_diarization: bool = False, | ||||||||||||||||||
| diarize_model: NotGivenOr[str] = NOT_GIVEN, | ||||||||||||||||||
| # enable filler words by default to improve turn detector accuracy | ||||||||||||||||||
| filler_words: bool = True, | ||||||||||||||||||
| keywords: NotGivenOr[list[tuple[str, float]]] = NOT_GIVEN, | ||||||||||||||||||
|
|
@@ -117,6 +119,11 @@ def __init__( | |||||||||||||||||
| sample_rate: The sample rate of the audio in Hz. Defaults to 16000. | ||||||||||||||||||
| no_delay: When smart_format is used, ensures it does not wait for sequence to be complete before returning results. Defaults to True. | ||||||||||||||||||
| endpointing_ms: Time in milliseconds of silence to consider end of speech. Set to 0 to disable. Defaults to 25. | ||||||||||||||||||
| diarize_model: Select the speaker diarization model version. Enabling this turns on | ||||||||||||||||||
| diarization without also needing ``enable_diarization``. Accepts "latest" | ||||||||||||||||||
| (newest GA diarizer), "v2" (improved batch diarizer, pre-recorded only) or "v1" | ||||||||||||||||||
| (original diarizer). The "v2" value is not supported for streaming requests. | ||||||||||||||||||
| See https://developers.deepgram.com/docs/diarization for details. Defaults to NOT_GIVEN. | ||||||||||||||||||
| filler_words: Whether to include filler words (um, uh, etc.) in transcription. Defaults to True. | ||||||||||||||||||
| keywords: List of tuples containing keywords and their boost values for improved recognition. | ||||||||||||||||||
| Each tuple should be (keyword: str, boost: float). Defaults to None. | ||||||||||||||||||
|
|
@@ -144,11 +151,14 @@ def __init__( | |||||||||||||||||
| the DEEPGRAM_API_KEY environmental variable. | ||||||||||||||||||
| """ # noqa: E501 | ||||||||||||||||||
|
|
||||||||||||||||||
| # diarize_model implies diarization without also needing enable_diarization | ||||||||||||||||||
| _diarization_enabled = enable_diarization or is_given(diarize_model) | ||||||||||||||||||
|
|
||||||||||||||||||
| super().__init__( | ||||||||||||||||||
| capabilities=stt.STTCapabilities( | ||||||||||||||||||
| streaming=True, | ||||||||||||||||||
| interim_results=interim_results, | ||||||||||||||||||
| diarization=enable_diarization, | ||||||||||||||||||
| diarization=_diarization_enabled, | ||||||||||||||||||
| aligned_transcript="word", | ||||||||||||||||||
| ) | ||||||||||||||||||
| ) | ||||||||||||||||||
|
|
@@ -186,6 +196,7 @@ def __init__( | |||||||||||||||||
| keyterm=keyterm if is_given(keyterm) else [], | ||||||||||||||||||
| profanity_filter=profanity_filter, | ||||||||||||||||||
| redact=redact if is_given(redact) else [], | ||||||||||||||||||
| diarize_model=diarize_model if is_given(diarize_model) else "", | ||||||||||||||||||
| numerals=numerals, | ||||||||||||||||||
| mip_opt_out=mip_opt_out, | ||||||||||||||||||
| vad_events=vad_events, | ||||||||||||||||||
|
|
@@ -232,6 +243,8 @@ async def _recognize_impl( | |||||||||||||||||
| recognize_config["keyterm"] = self._opts.keyterm | ||||||||||||||||||
| if config.redact: | ||||||||||||||||||
| recognize_config["redact"] = config.redact | ||||||||||||||||||
| if config.diarize_model: | ||||||||||||||||||
| recognize_config["diarize_model"] = config.diarize_model | ||||||||||||||||||
| if config.enable_diarization: | ||||||||||||||||||
| logger.warning("speaker diarization is not supported in non-streaming mode, ignoring") | ||||||||||||||||||
|
Comment on lines
+246
to
249
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚩 Pre-recorded path also missing diarize=True for diarize_model In Was this helpful? React with 👍 or 👎 to provide feedback. |
||||||||||||||||||
|
|
||||||||||||||||||
|
|
@@ -299,6 +312,7 @@ def update_options( | |||||||||||||||||
| no_delay: NotGivenOr[bool] = NOT_GIVEN, | ||||||||||||||||||
| endpointing_ms: NotGivenOr[int] = NOT_GIVEN, | ||||||||||||||||||
| enable_diarization: NotGivenOr[bool] = NOT_GIVEN, | ||||||||||||||||||
| diarize_model: NotGivenOr[str] = NOT_GIVEN, | ||||||||||||||||||
| filler_words: NotGivenOr[bool] = NOT_GIVEN, | ||||||||||||||||||
| keywords: NotGivenOr[list[tuple[str, float]]] = NOT_GIVEN, | ||||||||||||||||||
| keyterm: NotGivenOr[str | list[str]] = NOT_GIVEN, | ||||||||||||||||||
|
|
@@ -332,6 +346,8 @@ def update_options( | |||||||||||||||||
| self._opts.endpointing_ms = endpointing_ms | ||||||||||||||||||
| if is_given(enable_diarization): | ||||||||||||||||||
| self._opts.enable_diarization = enable_diarization | ||||||||||||||||||
| if is_given(diarize_model): | ||||||||||||||||||
| self._opts.diarize_model = diarize_model | ||||||||||||||||||
| if is_given(filler_words): | ||||||||||||||||||
| self._opts.filler_words = filler_words | ||||||||||||||||||
| if is_given(keywords): | ||||||||||||||||||
|
|
@@ -368,6 +384,7 @@ def update_options( | |||||||||||||||||
| sample_rate=sample_rate, | ||||||||||||||||||
| no_delay=no_delay, | ||||||||||||||||||
| endpointing_ms=endpointing_ms, | ||||||||||||||||||
| diarize_model=diarize_model, | ||||||||||||||||||
| filler_words=filler_words, | ||||||||||||||||||
| keywords=keywords, | ||||||||||||||||||
| keyterm=keyterm, | ||||||||||||||||||
|
Comment on lines
384
to
390
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚩 Pre-existing: enable_diarization not forwarded to streams in update_options In (Refers to lines 374-394) Was this helpful? React with 👍 or 👎 to provide feedback. |
||||||||||||||||||
|
|
@@ -444,6 +461,7 @@ def update_options( | |||||||||||||||||
| no_delay: NotGivenOr[bool] = NOT_GIVEN, | ||||||||||||||||||
| endpointing_ms: NotGivenOr[int] = NOT_GIVEN, | ||||||||||||||||||
| enable_diarization: NotGivenOr[bool] = NOT_GIVEN, | ||||||||||||||||||
| diarize_model: NotGivenOr[str] = NOT_GIVEN, | ||||||||||||||||||
| filler_words: NotGivenOr[bool] = NOT_GIVEN, | ||||||||||||||||||
| keywords: NotGivenOr[list[tuple[str, float]]] = NOT_GIVEN, | ||||||||||||||||||
| keyterm: NotGivenOr[str | list[str]] = NOT_GIVEN, | ||||||||||||||||||
|
|
@@ -477,6 +495,8 @@ def update_options( | |||||||||||||||||
| self._opts.endpointing_ms = endpointing_ms | ||||||||||||||||||
| if is_given(enable_diarization): | ||||||||||||||||||
| self._opts.enable_diarization = enable_diarization | ||||||||||||||||||
| if is_given(diarize_model): | ||||||||||||||||||
| self._opts.diarize_model = diarize_model | ||||||||||||||||||
| if is_given(filler_words): | ||||||||||||||||||
| self._opts.filler_words = filler_words | ||||||||||||||||||
| if is_given(keywords): | ||||||||||||||||||
|
|
@@ -653,6 +673,8 @@ async def _connect_ws(self) -> aiohttp.ClientWebSocketResponse: | |||||||||||||||||
| } | ||||||||||||||||||
| if self._opts.enable_diarization: | ||||||||||||||||||
| live_config["diarize"] = True | ||||||||||||||||||
| if self._opts.diarize_model: | ||||||||||||||||||
| live_config["diarize_model"] = self._opts.diarize_model | ||||||||||||||||||
|
Comment on lines
674
to
+677
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔴 Missing diarize=True in streaming config when diarize_model is set without enable_diarization In
Suggested change
Was this helpful? React with 👍 or 👎 to provide feedback. |
||||||||||||||||||
| if self._opts.keywords: | ||||||||||||||||||
| live_config["keywords"] = self._opts.keywords | ||||||||||||||||||
| if self._opts.keyterm: | ||||||||||||||||||
|
|
||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.