Skip to content

TransducerRecognizer support#98

Merged
thewh1teagle merged 9 commits intothewh1teagle:mainfrom
rdcm:from_transducer_example
May 12, 2025
Merged

TransducerRecognizer support#98
thewh1teagle merged 9 commits intothewh1teagle:mainfrom
rdcm:from_transducer_example

Conversation

@rdcm
Copy link
Contributor

@rdcm rdcm commented May 4, 2025

Hi! I'm currently migrating our speech-to-text service from Python to Rust. Our service relies on the from_transducer API from the original library, and it would be great to have the same API available in sherpa-rs. I still need to add a test, which might take a bit more time. In the meantime, if you have any comments or suggestions regarding the PR, I'm happy to discuss and make changes as needed.

TODO:
- tests (done)

Run tests:

  • cargo test transducer

Prerequisites:

@rdcm
Copy link
Contributor Author

rdcm commented May 5, 2025

@thewh1teagle test added, pr ready for review

@thewh1teagle
Copy link
Owner

Hi @rdcm
Can you omit the test and add example instead?
Let me know then if the example works :)

@thewh1teagle
Copy link
Owner

Follow the other examples template you can copy paste and change a bit

@rdcm
Copy link
Contributor Author

rdcm commented May 9, 2025

@thewh1teagle done, example added :)

@thewh1teagle
Copy link
Owner

Two things I noticed:
(1) when filling sherpa structs, instead of filling every inner struct with nulls we can use mem::zero<_>() it's very cool pattern I used in other files, this way we don't need many structs, the downside is that we need to create the main struct in unsafe block, but it's not big deal imo

(2) in the example instead of filling nulls, you can use ..Default::default() like in other examples

@thewh1teagle
Copy link
Owner

Feel free to leave it as is, I'll merge it anyway soon : )

@rdcm
Copy link
Contributor Author

rdcm commented May 11, 2025

@thewh1teagle

  1. Interesting approach, but not used across whole project, for example in whisper.rs and zipformer.rs nulls passed to structs explicitly - done.

  2. Done.

Example still works fine :)

@rdcm
Copy link
Contributor Author

rdcm commented May 11, 2025

Also added more detailed example.

@thewh1teagle
Copy link
Owner

Looks great. Thank you!

@thewh1teagle thewh1teagle merged commit 39b5cb7 into thewh1teagle:main May 12, 2025
3 checks passed
}

let config = TransducerConfig {
decoder: "decoder.onnx".to_string(),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thewh1teagle Hi, do you know if there is any way to pass &[u8] instead of a file path to the model?
Currently, we use a workaround with a memfd_create call to get a file descriptor for the memory and then pass the path to that descriptor.

However, ONNX Runtime provides a more convenient API, for example:

Session::builder()
   ....
   .commit_from_memory(model);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants