diff --git a/packages/server/src/api/local.ts b/packages/server/src/api/local.ts index ff2528ce..9d67dd5c 100644 --- a/packages/server/src/api/local.ts +++ b/packages/server/src/api/local.ts @@ -1,6 +1,6 @@ import fs from 'node:fs'; import multer from 'multer'; -import { join } from 'node:path'; +import { join, dirname } from 'node:path'; import { Application } from 'express'; import { exec } from 'child_process'; import { getImgsByImgUrl, getAudiosByAudioUrl, getVideosByVideoUrl } from '../util/index'; @@ -142,4 +142,11 @@ export function initLocalApi(app: Application) { exec(`start "" "${folderPath}"`); res.json({ code: 0 }); }); + + app.get('/openFilePath', async (req, res) => { + const filePath = req.query.filePath as string; + const folderPath = dirname(filePath); + exec(`start "" "${folderPath}"`); + res.json({ code: 0 }); + }); } diff --git a/packages/web/CHANGELOG.md b/packages/web/CHANGELOG.md index 7bfa4c76..1b3fb844 100644 --- a/packages/web/CHANGELOG.md +++ b/packages/web/CHANGELOG.md @@ -1,5 +1,9 @@ # @pear-rec/web +## 1.2.14 + +fix: 录音选择格式 + ## 1.2.13 fix: electron 录屏 bug diff --git a/packages/web/src/api/index.ts b/packages/web/src/api/index.ts index 293b5bdc..ed507b1b 100644 --- a/packages/web/src/api/index.ts +++ b/packages/web/src/api/index.ts @@ -15,6 +15,12 @@ export function useApi() { method: 'get', }); }, + openFilePath: (filePath) => { + return request({ + url: `/openFilePath?filePath=${filePath}`, + method: 'get', + }); + }, getFile: (url) => { return request({ url: `/getFile?url=${url}`, diff --git a/packages/web/src/components/recorderAudio/AudioRecorder.tsx b/packages/web/src/components/recorderAudio/AudioRecorder.tsx index bac14e99..2436164a 100644 --- a/packages/web/src/components/recorderAudio/AudioRecorder.tsx +++ b/packages/web/src/components/recorderAudio/AudioRecorder.tsx @@ -13,10 +13,12 @@ const AudioRecorder = (props) => { const timer = useTimer(); const micRef = useRef(); const audioInputOptions = useRef(); + const mimeTypesOptions = useRef(); const [record, setRecord] = useState(null); const [isOpenMic, setIsOpenMic] = useState(false); const [recordStatus, setRecordStatus] = useState(''); const [deviceId, setDeviceId] = useState(''); + const [mimeType, setMimeType] = useState('audio/webm'); useEffect(() => { if (!micRef.current) return; @@ -26,7 +28,7 @@ const AudioRecorder = (props) => { progressColor: 'rgb(100, 0, 100)', }); - const record = wavesurfer.registerPlugin(RecordPlugin.create() as any); + const record = wavesurfer.registerPlugin(RecordPlugin.create({ mimeType }) as any); record.getEnumerateDevices().then((deviceInfos) => { let _audioInputOptions = [ @@ -47,6 +49,17 @@ const AudioRecorder = (props) => { audioInputOptions.current = _audioInputOptions; }); + const mimeTypes = record.getSupportedMimeTypes(); + let _mimeTypesOptions = []; + for (let i = 0; i < mimeTypes.length; i++) { + const mimeType = mimeTypes[i]; + _mimeTypesOptions.push({ + value: mimeType, + label: mimeType, + }); + } + mimeTypesOptions.current = _mimeTypesOptions; + record.on('record-start', () => { console.log('record-start'); timer.start(); @@ -138,6 +151,10 @@ const AudioRecorder = (props) => { isOpenMic && record.startMic(value); } + function handleChangeMimeType(value) { + setMimeType(value); + } + return ( @@ -150,6 +167,13 @@ const AudioRecorder = (props) => { onChange={handleChangeSource} options={audioInputOptions.current} /> + 格式 +