mirror of
https://github.com/cgzirim/seek-tune.git
synced 2025-12-17 00:44:19 +00:00
feat: Add support for stereo audio recording
This commit is contained in:
parent
14df5b3845
commit
46d08c7fea
1 changed files with 13 additions and 8 deletions
|
|
@ -15,7 +15,8 @@ import { fetchFile } from '@ffmpeg/util';
|
||||||
|
|
||||||
import AnimatedNumber from "./components/AnimatedNumber";
|
import AnimatedNumber from "./components/AnimatedNumber";
|
||||||
|
|
||||||
const server = process.env.REACT_APP_BACKEND_URL || "http://localhost:5000";
|
const server = process.env.REACT_APP_BACKEND_URL || "http://localhost:5500";
|
||||||
|
const recordStereo = process.env.REACT_APP_RECORD_STEREO === "true" || false;
|
||||||
// https://seek-tune-rq4gn.ondigitalocean.app/
|
// https://seek-tune-rq4gn.ondigitalocean.app/
|
||||||
|
|
||||||
var socket = io(server);
|
var socket = io(server);
|
||||||
|
|
@ -175,15 +176,15 @@ function App() {
|
||||||
cleanUp();
|
cleanUp();
|
||||||
|
|
||||||
const inputFile = 'input.wav';
|
const inputFile = 'input.wav';
|
||||||
const outputFile = 'output_mono.wav';
|
const outputFile = 'output_formatted.wav';
|
||||||
|
|
||||||
// Convert audio to mono with a sample rate of 44100 Hz
|
|
||||||
await ffmpeg.writeFile(inputFile, await fetchFile(blob))
|
await ffmpeg.writeFile(inputFile, await fetchFile(blob))
|
||||||
const exitCode = await ffmpeg.exec([
|
const exitCode = await ffmpeg.exec([
|
||||||
'-i', inputFile,
|
'-i', inputFile,
|
||||||
'-c', 'pcm_s16le',
|
'-c', 'pcm_s16le',
|
||||||
'-ar', '44100',
|
'-ar', '44100',
|
||||||
'-ac', '1',
|
'-ac', recordStereo ? '2' : '1',
|
||||||
|
'-acodec', 'pcm_s16le',
|
||||||
'-f', 'wav',
|
'-f', 'wav',
|
||||||
outputFile
|
outputFile
|
||||||
]);
|
]);
|
||||||
|
|
@ -191,11 +192,11 @@ function App() {
|
||||||
throw new Error(`FFmpeg exec failed with exit code: ${exitCode}`);
|
throw new Error(`FFmpeg exec failed with exit code: ${exitCode}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const monoData = await ffmpeg.readFile(outputFile);
|
const audioData = await ffmpeg.readFile(outputFile);
|
||||||
const monoBlob = new Blob([monoData.buffer], { type: 'audio/wav' });
|
const audioBlob = new Blob([audioData.buffer], { type: 'audio/wav' });
|
||||||
|
|
||||||
const reader = new FileReader();
|
const reader = new FileReader();
|
||||||
reader.readAsArrayBuffer(monoBlob);
|
reader.readAsArrayBuffer(audioBlob);
|
||||||
reader.onload = async (event) => {
|
reader.onload = async (event) => {
|
||||||
const arrayBuffer = event.target.result;
|
const arrayBuffer = event.target.result;
|
||||||
const audioContext = new AudioContext();
|
const audioContext = new AudioContext();
|
||||||
|
|
@ -205,7 +206,11 @@ function App() {
|
||||||
const audioData = audioBufferDecoded.getChannelData(0);
|
const audioData = audioBufferDecoded.getChannelData(0);
|
||||||
const audioArray = Array.from(audioData);
|
const audioArray = Array.from(audioData);
|
||||||
|
|
||||||
const result = genFingerprint(audioArray, audioBufferDecoded.sampleRate);
|
const result = genFingerprint(
|
||||||
|
audioArray,
|
||||||
|
audioBufferDecoded.sampleRate,
|
||||||
|
audioBufferDecoded.numberOfChannels
|
||||||
|
);
|
||||||
if (result.error !== 0) {
|
if (result.error !== 0) {
|
||||||
toast["error"](() => <div>An error occured</div>)
|
toast["error"](() => <div>An error occured</div>)
|
||||||
console.log("An error occured: ", result)
|
console.log("An error occured: ", result)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue