Skip to content

Commit 1a01610

Browse files
committed
fix: Use proper blob encoding in audio annotator. Closes #2174.
1 parent b5e596e commit 1a01610

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

ui/src/audio_annotator.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,14 @@ const
7777
{ key: 1.5, text: '1.5x' },
7878
{ key: 2, text: '2x' },
7979
],
80+
audioMimeTypes = {
81+
mp3: 'audio/mpeg',
82+
wav: 'audio/wav',
83+
ogg: 'audio/ogg',
84+
flac: 'audio/flac',
85+
aac: 'audio/aac',
86+
m4a: 'audio/mp4',
87+
},
8088
// Love ya Safari.
8189
promisifyDecodeAudioData = (audioContext: AudioContext, audioData: ArrayBuffer) => new Promise<AudioBuffer>((resolve, reject) => {
8290
audioContext.decodeAudioData(audioData, resolve, reject)
@@ -125,9 +133,11 @@ export const XAudioAnnotator = ({ model }: { model: AudioAnnotator }) => {
125133
setErrMsg('Could not download audio file.')
126134
return
127135
}
136+
const ext = model.path.split('.').pop()?.toLowerCase() as keyof typeof audioMimeTypes
137+
const type = audioMimeTypes[ext] || 'audio/mpeg'
128138
// Store the URL into the ref so that it can be revoked on destroy and mem leak prevented.
129139
// Safari needs Blob type to be specified, doesn't need to match the real sound format.
130-
fetchedAudioUrlRef.current = URL.createObjectURL(new Blob([arrBuffer], { type: 'audio/mpeg' }))
140+
fetchedAudioUrlRef.current = URL.createObjectURL(new Blob([arrBuffer], { type }))
131141
// Do not set src directly within HTML to prevent double fetching.
132142
audioRef.current.src = fetchedAudioUrlRef.current
133143

0 commit comments

Comments
 (0)