Skip to content

Commit

Permalink
Fix recording incomplete (#591)
Browse files Browse the repository at this point in the history
* upgrade deps

* disable denoise for recording
  • Loading branch information
an-lee committed May 7, 2024
1 parent db912e2 commit 107fa97
Show file tree
Hide file tree
Showing 4 changed files with 266 additions and 120 deletions.
4 changes: 2 additions & 2 deletions 1000-hours/package.json
Expand Up @@ -8,10 +8,10 @@
"markdown-it-sub": "^2.0.0",
"markdown-it-sup": "^2.0.0",
"mermaid": "^10.9.0",
"sass": "^1.76.0",
"sass": "^1.77.0",
"vitepress": "^1.1.4",
"vitepress-plugin-mermaid": "^2.0.16",
"vue": "^3.4.26"
"vue": "^3.4.27"
},
"scripts": {
"dev": "vitepress dev",
Expand Down
10 changes: 5 additions & 5 deletions enjoy/package.json
Expand Up @@ -41,7 +41,7 @@
"@electron-forge/plugin-vite": "^7.4.0",
"@electron-forge/publisher-github": "^7.4.0",
"@electron/fuses": "^1.8.0",
"@playwright/test": "^1.43.1",
"@playwright/test": "^1.44.0",
"@tailwindcss/typography": "^0.5.13",
"@types/autosize": "^4.0.3",
"@types/command-exists": "^1.2.3",
Expand All @@ -51,7 +51,7 @@
"@types/intl-tel-input": "^18.1.4",
"@types/lodash": "^4.17.1",
"@types/mark.js": "^8.11.12",
"@types/node": "^20.12.8",
"@types/node": "^20.12.10",
"@types/react": "^18.3.1",
"@types/react-dom": "^18.3.0",
"@types/validator": "^13.11.9",
Expand Down Expand Up @@ -83,7 +83,7 @@
"@andrkrn/ffprobe-static": "^5.2.0",
"@electron-forge/publisher-s3": "^7.4.0",
"@hookform/resolvers": "^3.3.4",
"@langchain/community": "^0.0.54",
"@langchain/community": "^0.0.55",
"@langchain/google-genai": "^0.0.12",
"@mozilla/readability": "^0.5.0",
"@radix-ui/react-accordion": "^1.1.2",
Expand Down Expand Up @@ -130,7 +130,7 @@
"decamelize": "^6.0.0",
"decamelize-keys": "^2.0.1",
"echogarden": "^1.3.0",
"electron-context-menu": "^3.6.1",
"electron-context-menu": "^4.0.0",
"electron-log": "^5.1.2",
"electron-settings": "^4.0.4",
"electron-squirrel-startup": "^1.0.0",
Expand All @@ -148,7 +148,7 @@
"mark.js": "^8.11.1",
"microsoft-cognitiveservices-speech-sdk": "^1.36.0",
"next-themes": "^0.3.0",
"openai": "^4.40.2",
"openai": "^4.42.0",
"pitchfinder": "^2.3.2",
"postcss": "^8.4.38",
"proxy-agent": "^6.4.0",
Expand Down
20 changes: 12 additions & 8 deletions enjoy/src/main/db/models/recording.ts
Expand Up @@ -306,22 +306,26 @@ export class Recording extends Model<Recording> {
throw new Error("Empty recording");
}

// denoise audio
const { denoisedAudio } = await echogarden.denoise(
Buffer.from(blob.arrayBuffer),
{}
let rawAudio = await echogarden.ensureRawAudio(
Buffer.from(blob.arrayBuffer)
);

// denoise audio
// const { denoisedAudio } = await echogarden.denoise(
// rawAudio,
// {}
// );

// trim audio
let trimmedSamples = echogarden.trimAudioStart(
denoisedAudio.audioChannels[0],
rawAudio.audioChannels[0],
0,
-30
);
trimmedSamples = echogarden.trimAudioEnd(trimmedSamples, 0, -30);
denoisedAudio.audioChannels[0] = trimmedSamples;
rawAudio.audioChannels[0] = trimmedSamples;

duration = Math.round(echogarden.getRawAudioDuration(denoisedAudio) * 1000);
duration = Math.round(echogarden.getRawAudioDuration(rawAudio) * 1000);

if (duration === 0) {
throw new Error("Failed to get duration of the recording");
Expand All @@ -333,7 +337,7 @@ export class Recording extends Model<Recording> {
"recordings",
`${Date.now()}.wav`
);
await fs.outputFile(file, echogarden.encodeRawAudioToWave(denoisedAudio));
await fs.outputFile(file, echogarden.encodeRawAudioToWave(rawAudio));

// hash file
const md5 = await hashFile(file, { algo: "md5" });
Expand Down

0 comments on commit 107fa97

Please sign in to comment.