-
Notifications
You must be signed in to change notification settings - Fork 333
Nvidia Parakeet Tdt ASR support #2150
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 34 commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
1892ba7
Start parakeet v3
nenad1002 6d88f75
More fixes
nenad1002 8ae481c
remove streaming asr for parakeet
nenad1002 8d2c201
use extensions for mel
nenad1002 a242ea4
Match nemotron genai_config structure
nenad1002 f338e8f
More changes
nenad1002 9471780
Parakeet processor changes
nenad1002 922fce6
refactor class names
nenad1002 1ad4ec4
calculate mel spec for full audio
nenad1002 e104b3e
Move mel to processor
nenad1002 25c489b
More bug fixes
nenad1002 0f79878
Add tests
nenad1002 75e53c1
Fix sample
nenad1002 8d49f62
Processor changes
nenad1002 6d6a973
Better comments
nenad1002 8f5a7b3
Do proper output streaming
nenad1002 224f7f8
More comments resolving
nenad1002 41ead0c
Cuda support
nenad1002 16ac1fd
Remove eos token
nenad1002 b7b632f
Clean comments
nenad1002 bc0e09f
Tests reference
nenad1002 397d4a3
Fix tests
nenad1002 ea3dcc3
Copilot fixes
nenad1002 c602b9e
Correct CUDA streaming
nenad1002 bb91efe
Place input/output tensors on CPU, let ORT decide placement
nenad1002 495e901
Copilot comments
nenad1002 5f05ad7
Try fix Windows compile issues
nenad1002 41926a1
Resolve comments 1
nenad1002 f4fad6c
Resolve comments 2
nenad1002 3a00258
Introduce tranducer state
nenad1002 a8a38f9
Fix comments
nenad1002 2c75080
fix merge conflict
nenad1002 d076a05
Add heartbeat output for long Windows CUDA CI steps
Copilot 4a2f1bf
Revert "Add heartbeat output for long Windows CUDA CI steps"
nenad1002 c22fe86
Fix memory leak
nenad1002 81fb240
Merge branch 'main' into nebanfic/parakeet-new-v3
nenad1002 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,99 @@ | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. | ||
| """ | ||
| Parakeet TDT speech recognition | ||
|
|
||
| python parakeet.py --model_path <model_dir> --audio_file <audio> | ||
|
|
||
| The model loads the audio in one shot and decodes it with the standard | ||
| Generator loop. | ||
| """ | ||
|
|
||
| import argparse | ||
| import os | ||
| import time | ||
| import wave | ||
|
|
||
| import onnxruntime_genai as og | ||
|
|
||
|
|
||
| def _audio_duration_seconds(path: str) -> float: | ||
| try: | ||
| with wave.open(path, "rb") as wf: | ||
| frames = wf.getnframes() | ||
| rate = wf.getframerate() | ||
| if rate > 0: | ||
| return frames / float(rate) | ||
| except wave.Error: | ||
|
github-advanced-security[bot] marked this conversation as resolved.
Fixed
|
||
| # Not a valid/parsable WAV stream; fall back to soundfile below. | ||
| pass | ||
| try: | ||
| import soundfile as sf # type: ignore | ||
| info = sf.info(path) | ||
| return float(info.frames) / float(info.samplerate) | ||
| except Exception: | ||
| # soundfile missing or file unreadable; duration is non-essential | ||
| # for this sample, so return 0.0 rather than failing the run. | ||
| return 0.0 | ||
|
|
||
|
|
||
| def run(args: argparse.Namespace) -> None: | ||
| print("Loading model...") | ||
| config = og.Config(args.model_path) | ||
| if args.execution_provider != "follow_config": | ||
| config.clear_providers() | ||
| if args.execution_provider != "cpu": | ||
| print(f"Setting model to {args.execution_provider}") | ||
| config.append_provider(args.execution_provider) | ||
| model = og.Model(config) | ||
| processor = model.create_multimodal_processor() | ||
|
|
||
| if not os.path.exists(args.audio_file): | ||
| raise FileNotFoundError(f"Audio file not found: {args.audio_file}") | ||
|
|
||
| print(f"Loading audio: {args.audio_file}") | ||
| audios = og.Audios.open(args.audio_file) | ||
| audio_seconds = _audio_duration_seconds(args.audio_file) | ||
|
|
||
| print("Processing audio...") | ||
| t0 = time.perf_counter() | ||
| inputs = processor("", audios=audios) | ||
|
|
||
| params = og.GeneratorParams(model) | ||
|
|
||
| generator = og.Generator(model, params) | ||
| generator.set_inputs(inputs) | ||
|
|
||
| while not generator.is_done(): | ||
| generator.generate_next_token() | ||
| elapsed = time.perf_counter() - t0 | ||
|
|
||
| transcription = processor.decode(generator.get_sequence(0)) | ||
|
|
||
| print() | ||
| print("Transcription:") | ||
| print(f" {transcription.strip()}") | ||
|
|
||
| print() | ||
| if audio_seconds > 0: | ||
| rtfx = audio_seconds / elapsed if elapsed > 0 else float("inf") | ||
| print(f"Audio duration: {audio_seconds:.2f}s | Inference: {elapsed:.2f}s | RTFx: {rtfx:.2f}x") | ||
| else: | ||
| print(f"Inference: {elapsed:.2f}s") | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| parser = argparse.ArgumentParser() | ||
| parser.add_argument("-m", "--model_path", type=str, required=True, help="Path to the Parakeet model directory") | ||
| parser.add_argument("-a", "--audio_file", type=str, required=True, help="Path to the audio file (WAV/MP3/...)") | ||
| parser.add_argument( | ||
| "-e", | ||
| "--execution_provider", | ||
| type=str, | ||
| required=False, | ||
| default="follow_config", | ||
| choices=["cpu", "cuda", "follow_config"], | ||
| help="Execution provider. Defaults to follow_config.", | ||
| ) | ||
| args = parser.parse_args() | ||
| run(args) | ||
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
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
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
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.