auto-git:
[add] dist/assets/index-BFOWWhCS.css [add] dist/assets/index-Dm7DZNSo.js [change] dist/index.html [change] electron/main.cjs [change] src/App.jsx [unlink] dist/assets/index-CQjkNPEp.js [unlink] dist/assets/index-CzQQplJ5.css
This commit is contained in:
17
src/App.jsx
17
src/App.jsx
@@ -533,18 +533,27 @@ export default function App() {
|
||||
|
||||
try {
|
||||
const dataUrl = await readFileAsDataUrl(blob)
|
||||
const match = /^data:([^;]+);base64,([\s\S]+)$/i.exec(dataUrl)
|
||||
if (!match) {
|
||||
const commaIndex = dataUrl.indexOf(',')
|
||||
if (commaIndex <= 5) {
|
||||
throw new Error('Recorded audio could not be encoded for upload.')
|
||||
}
|
||||
const header = dataUrl.slice(0, commaIndex)
|
||||
const payload = dataUrl.slice(commaIndex + 1)
|
||||
if (!/^data:[^,]+;base64$/i.test(header) || !payload) {
|
||||
throw new Error('Recorded audio could not be encoded for upload.')
|
||||
}
|
||||
const detectedMimeType = header
|
||||
.slice(5)
|
||||
.replace(/;base64$/i, '')
|
||||
.trim()
|
||||
|
||||
const response = await fetch(`${backendApiUrl}/audio/transcribe`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
signal: controller.signal,
|
||||
body: JSON.stringify({
|
||||
mime_type: mimeType || match[1] || 'audio/webm',
|
||||
audio_base64: match[2],
|
||||
mime_type: mimeType || detectedMimeType || 'audio/webm',
|
||||
audio_base64: payload,
|
||||
}),
|
||||
})
|
||||
const data = await expectBackendJson(response)
|
||||
|
||||
Reference in New Issue
Block a user