-
Notifications
You must be signed in to change notification settings - Fork 5
Add ElevenLabs Custom Vocab & Orchestration pipeline #93
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
Merged
Merged
Changes from 4 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
b28b6cc
Add elevenlabs custom vocab
76c9d1c
Refactor benchmarks.md
6258a4e
Add elevenlabs no keywords results
fb7f58a
reformat
401368b
update elevenlabs chunkwise results
f145504
Add support for force_language input
a2012d3
reformat
8e0e1c4
Add Elevenlabs Orchestration Pipeline (#94)
dbrkn 5a1864c
reformat
e03ead6
Flip keyword recognition tables
4ebc4f2
Refactor table column names
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| ElevenLabsTranscriptionPipeline: | ||
| config: | ||
| model_id: "scribe_v2" | ||
| use_keywords: true | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
src/openbench/pipeline/transcription/transcription_elevenlabs.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| import os | ||
| from pathlib import Path | ||
| from typing import Callable | ||
|
|
||
| from argmaxtools.utils import get_logger | ||
| from elevenlabs.client import ElevenLabs | ||
| from pydantic import Field | ||
|
|
||
| from ...dataset import TranscriptionSample | ||
| from ...pipeline import Pipeline, register_pipeline | ||
| from ...pipeline_prediction import Transcript | ||
| from ...types import PipelineType | ||
| from .common import TranscriptionConfig, TranscriptionOutput | ||
|
|
||
|
|
||
| logger = get_logger(__name__) | ||
|
|
||
| TEMP_AUDIO_DIR = Path("temp_audio_dir") | ||
|
|
||
|
|
||
| class ElevenLabsTranscriptionPipelineConfig(TranscriptionConfig): | ||
| model_id: str = Field( | ||
| default="scribe_v2", | ||
| description="The ElevenLabs speech-to-text model to use", | ||
| ) | ||
|
|
||
|
|
||
| @register_pipeline | ||
| class ElevenLabsTranscriptionPipeline(Pipeline): | ||
| _config_class = ElevenLabsTranscriptionPipelineConfig | ||
| pipeline_type = PipelineType.TRANSCRIPTION | ||
|
|
||
| def build_pipeline(self) -> Callable[[Path], str]: | ||
| api_key = os.getenv("ELEVENLABS_API_KEY") | ||
| assert api_key is not None, "Please set ELEVENLABS_API_KEY in environment" | ||
|
|
||
| client = ElevenLabs(api_key=api_key) | ||
|
|
||
| def transcribe(audio_path: Path) -> str: | ||
| with open(audio_path, "rb") as f: | ||
| audio_data = f.read() | ||
|
|
||
| kwargs = { | ||
| "file": audio_data, | ||
| "model_id": self.config.model_id, | ||
| } | ||
|
|
||
| # Add keyterms if available (up to 100, max 50 chars each) | ||
| if self.current_keywords: | ||
| # Filter keywords to max 50 chars and limit to 100 | ||
| filtered_keywords = [kw[:50] for kw in self.current_keywords[:100]] | ||
| kwargs["keyterms"] = filtered_keywords | ||
| logger.debug(f"Using keyterms: {filtered_keywords}") | ||
|
|
||
| transcription = client.speech_to_text.convert(**kwargs) | ||
|
|
||
| # Remove temporary audio path | ||
| audio_path.unlink(missing_ok=True) | ||
|
|
||
| return transcription.text | ||
|
|
||
| return transcribe | ||
|
|
||
| def parse_input(self, input_sample: TranscriptionSample) -> Path: | ||
| """Override to extract keywords from sample before processing.""" | ||
| self.current_keywords = None | ||
| if self.config.use_keywords: | ||
| keywords = input_sample.extra_info.get("dictionary", []) | ||
| if keywords: | ||
| self.current_keywords = keywords | ||
|
|
||
| # Warn if force_language is enabled (not currently supported) | ||
| if self.config.force_language: | ||
| logger.warning( | ||
| f"{self.__class__.__name__} does not support language hinting. " | ||
| "The force_language flag will be ignored." | ||
| ) | ||
|
|
||
| return input_sample.save_audio(TEMP_AUDIO_DIR) | ||
|
|
||
| def parse_output(self, output: str) -> TranscriptionOutput: | ||
| # Split transcript into words | ||
| words = output.split() if output else [] | ||
| transcript = Transcript.from_words_info(words=words) | ||
| return TranscriptionOutput(prediction=transcript) | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.