Skip to content

Conversation

@ammyt
Copy link

@ammyt ammyt commented Aug 5, 2025

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.

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.
@riderodd riderodd added the enhancement New feature or request label Aug 5, 2025
@riderodd
Copy link
Owner

riderodd commented Aug 5, 2025

Sounds good thank you ! Are you in position to do the iOS implementation ?

@ammyt
Copy link
Author

ammyt commented Aug 5, 2025

@riderodd never been in the Apple ecosystem but it should be straightforward I guess, just can't test it I suppose.

@riderodd
Copy link
Owner

Feel free to do it on iOS side, I'll be able to test if needed!

@riderodd riderodd requested a review from Copilot August 22, 2025 22:32
@riderodd riderodd self-assigned this Aug 22, 2025
Copy link
Contributor

Copilot AI left a 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)
}
Copy link

Copilot AI Aug 22, 2025

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.

Copilot uses AI. Check for mistakes.
promise.reject("TRANSCRIBE_FAIL", e)
} finally {
// Clean up
try { input?.close() } catch (_: IOException) { }
Copy link

Copilot AI Aug 22, 2025

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.

Suggested change
try { input?.close() } catch (_: IOException) { }
try { input?.close() } catch (e: IOException) { Log.e(NAME, "Failed to close input stream", e) }

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants