Skip to content

Commit d45c9b4

Browse files
authored
Merge pull request #9 from europanite/feature/develop
fix/mkv
2 parents 2cb60a7 + d246662 commit d45c9b4

3 files changed

Lines changed: 26 additions & 7 deletions

File tree

frontend/app/src/__tests__/HomeScreen.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ describe("HomeScreen", () => {
8282
) as HTMLInputElement;
8383

8484
expect(fileInput.accept).toBe(
85-
"audio/*,video/mp4,video/webm,video/ogg,.mp4,.webm,.ogv,.m4v"
85+
"audio/*,video/mp4,video/webm,video/ogg,video/x-matroska,video/matroska,.mp4,.webm,.ogv,.m4v,.mkv"
8686
);
8787
});
8888

frontend/app/src/hooks/useTranscription.ts

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,15 +139,34 @@ export function useTranscription(): UseTranscriptionResult {
139139
const asr = await loadModel(selectedModelIdState);
140140
setStatus("transcribing");
141141

142-
// --- Decode MP3 -> mono Float32Array on the client ---
142+
// --- Decode browser-supported audio/video -> mono Float32Array on the client ---
143143
// 1) Read file as ArrayBuffer
144144
const arrayBuffer = await file.arrayBuffer();
145145

146146
// 2) Decode and (effectively) resample to 16 kHz
147147
const audioContext = new AudioContext({ sampleRate: 16000 });
148-
const audioBuffer = await audioContext.decodeAudioData(
149-
arrayBuffer.slice(0)
150-
);
148+
let audioBuffer: AudioBuffer;
149+
150+
try {
151+
audioBuffer = await audioContext.decodeAudioData(
152+
arrayBuffer.slice(0)
153+
);
154+
} catch (decodeError) {
155+
const isMkv =
156+
file.name.toLowerCase().endsWith(".mkv") ||
157+
file.type === "video/x-matroska" ||
158+
file.type === "video/matroska";
159+
160+
if (isMkv) {
161+
throw new Error(
162+
"This browser could not decode the selected MKV file. " +
163+
"MKV selection is allowed, but transcription still depends on the browser's built-in media decoder. " +
164+
"Please try Chrome/Edge, or convert/extract the audio to MP3, WAV, M4A, MP4, or WebM."
165+
);
166+
}
167+
168+
throw decodeError;
169+
}
151170

152171
// 3) Mix all channels down to mono instead of fixing to channel 0
153172
const channelData = mixToMono(audioBuffer);

frontend/app/src/screens/HomeScreen.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ const HomeScreen = () => {
7474
<h2 className="section-title">Step 1 - Choose a model and media file</h2>
7575
<p className="section-description">
7676
Pick a multilingual Whisper model, then select your audio or video file.
77-
Whisper will automatically detect speech from supported media such as MP3 or MP4 in your browser.
77+
Whisper will automatically detect speech from supported media such as MP3, MP4, WebM, or browser-decodable MKV in your browser.
7878
</p>
7979

8080
<div className="field-group">
@@ -114,7 +114,7 @@ const HomeScreen = () => {
114114
<input
115115
ref={fileInputRef}
116116
type="file"
117-
accept="audio/*,video/mp4,video/webm,video/ogg,.mp4,.webm,.ogv,.m4v"
117+
accept="audio/*,video/mp4,video/webm,video/ogg,video/x-matroska,video/matroska,.mp4,.webm,.ogv,.m4v,.mkv"
118118
style={{ display: "none" }}
119119
onChange={handleFileChange}
120120
/>

0 commit comments

Comments
 (0)