-
Notifications
You must be signed in to change notification settings - Fork 25
Feat/transcribe file #140
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?
Feat/transcribe file #140
Conversation
Add a new `transcribeFile(wavPath: string): Promise<string>` method to the Vosk module. - Android: implement `@ReactMethod transcribeFile(...)` that streams a 16 kHz mono WAV into a new `Recognizer` and returns its final JSON result. - JS wrapper: expose `Vosk.transcribeFile = (wavPath) => VoskModule.transcribeFile(wavPath)` and update `VoskInterface` to include the new method.
Change method from java to kotlin.
|
Sounds good thank you ! Are you in position to do the iOS implementation ? |
|
@riderodd never been in the Apple ecosystem but it should be straightforward I guess, just can't test it I suppose. |
|
Feel free to do it on iOS side, I'll be able to test if needed! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Adds a new transcribeFile method to the Vosk React Native module that enables transcription of WAV files directly from disk without requiring live audio recording.
- Implements the transcription functionality in the Android native module using Vosk's Recognizer
- Exposes the method through the JavaScript wrapper with proper TypeScript typing
- Provides a complete solution for batch audio file processing
Reviewed Changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/index.tsx | Adds TypeScript wrapper for transcribeFile method with JSDoc documentation |
| android/src/main/java/com/vosk/VoskModule.kt | Implements native Android transcribeFile method with file streaming and error handling |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| // Read & feed each chunk | ||
| while (input.read(buffer).also { bytesRead = it } > 0) { | ||
| recognizer.acceptWaveForm(buffer, bytesRead) | ||
| } |
Copilot
AI
Aug 22, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The WAV file is being read from the beginning, which includes the WAV header. The header should be skipped to avoid feeding metadata to the recognizer. Consider using input.skip(44) before the read loop to skip the standard 44-byte WAV header, or implement proper WAV header parsing.
| promise.reject("TRANSCRIBE_FAIL", e) | ||
| } finally { | ||
| // Clean up | ||
| try { input?.close() } catch (_: IOException) { } |
Copilot
AI
Aug 22, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Silently catching and ignoring IOException when closing the file stream can hide important cleanup issues. Consider logging the exception or using a more specific exception handling approach.
| try { input?.close() } catch (_: IOException) { } | |
| try { input?.close() } catch (e: IOException) { Log.e(NAME, "Failed to close input stream", e) } |
Add a new
transcribeFile(wavPath: string): Promise<string>method to the Vosk module.@ReactMethod transcribeFile(...)that streams a 16 kHz mono WAVinto a new
Recognizerand returns its final JSON result.Vosk.transcribeFile = (wavPath) => VoskModule.transcribeFile(wavPath)and update
VoskInterfaceto include the new method.