Skip to content

Commit

Permalink
🐛 fix: Fix mine type in safari
Browse files Browse the repository at this point in the history
  • Loading branch information
canisminor1990 committed Nov 13, 2023
1 parent 801b6ae commit 8181a8e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
11 changes: 11 additions & 0 deletions src/const/mimeType.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export const RECORD_MIME_TYPE = () => {
return MediaRecorder.isTypeSupported('audio/webm')
? {
extension: 'webm',
mineType: 'audio/webm',
}
: {
extension: 'mp4',
mineType: 'audio/mp4',
};
};
5 changes: 3 additions & 2 deletions src/services/fetchOpenaiSTT.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { v4 as uuidv4 } from 'uuid';

import { OPENAI_API_KEY, OPENAI_STT_URL } from '@/const/api';
import { RECORD_MIME_TYPE } from '@/const/mimeType';

export interface OpenaiSttOptions {
api?: {
Expand All @@ -22,8 +23,8 @@ export const fetchOpenaiSTT = async (
Authorization: `Bearer ${key}`,
});

const filename = `${uuidv4()}.webm`;
const file = new File([speech], filename, { type: 'audio/webm' });
const filename = `${uuidv4()}.${RECORD_MIME_TYPE().extension}`;
const file = new File([speech], filename, { type: RECORD_MIME_TYPE().mineType });

const body = new FormData();
body.append('file', file);
Expand Down
5 changes: 4 additions & 1 deletion src/useAudioRecorder/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useCallback, useState } from 'react';

import { RECORD_MIME_TYPE } from '@/const/mimeType';
import { secondsToMinutesAndSeconds } from '@/utils/secondsToMinutesAndSeconds';

export const useAudioRecorder = (onBolbAvailable?: (blob: Blob) => void) => {
Expand Down Expand Up @@ -37,7 +38,9 @@ export const useAudioRecorder = (onBolbAvailable?: (blob: Blob) => void) => {
.getUserMedia({ audio: true })
.then((stream) => {
setIsRecording(true);
const recorder: MediaRecorder = new MediaRecorder(stream, { mimeType: 'audio/webm' });
const recorder: MediaRecorder = new MediaRecorder(stream, {
mimeType: RECORD_MIME_TYPE().mineType,
});
setMediaRecorder(recorder);
recorder.start();
_startTimer();
Expand Down

0 comments on commit 8181a8e

Please sign in to comment.