Skip to content

Commit

Permalink
Fix transcription (#1137)
Browse files Browse the repository at this point in the history
* upgrade deps

* fix generate transcription

* validate transcription before download from online
  • Loading branch information
an-lee authored Oct 20, 2024
1 parent ae4d245 commit d2c32d3
Show file tree
Hide file tree
Showing 5 changed files with 173 additions and 129 deletions.
2 changes: 1 addition & 1 deletion 1000-hours/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"markdown-it-sub": "^2.0.0",
"markdown-it-sup": "^2.0.0",
"mermaid": "^11.3.0",
"sass": "^1.80.1",
"sass": "^1.80.3",
"vitepress": "^1.4.1",
"vitepress-plugin-mermaid": "^2.0.17",
"vue": "^3.5.12"
Expand Down
2 changes: 1 addition & 1 deletion 1000h-portal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"devDependencies": {
"autoprefixer": "^10.4.20",
"postcss": "^8.4.47",
"sass": "^1.80.1",
"sass": "^1.80.3",
"tailwindcss": "^3.4.14"
}
}
24 changes: 12 additions & 12 deletions enjoy/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@
"@types/fluent-ffmpeg": "^2.1.26",
"@types/html-to-text": "^9.0.4",
"@types/intl-tel-input": "^18.1.4",
"@types/lodash": "^4.17.10",
"@types/lodash": "^4.17.12",
"@types/mark.js": "^8.11.12",
"@types/mustache": "^4.2.5",
"@types/node": "^22.7.6",
"@types/node": "^22.7.7",
"@types/prop-types": "^15.7.13",
"@types/rails__actioncable": "^6.1.11",
"@types/react": "^18.3.11",
Expand All @@ -61,14 +61,14 @@
"@types/unzipper": "^0.10.10",
"@types/validator": "^13.12.2",
"@types/wavesurfer.js": "^6.0.12",
"@typescript-eslint/eslint-plugin": "^8.9.0",
"@typescript-eslint/parser": "^8.9.0",
"@vitejs/plugin-react": "^4.3.2",
"@typescript-eslint/eslint-plugin": "^8.10.0",
"@typescript-eslint/parser": "^8.10.0",
"@vitejs/plugin-react": "^4.3.3",
"autoprefixer": "^10.4.20",
"electron": "^33.0.1",
"electron-devtools-installer": "^3.2.0",
"electron-playwright-helpers": "^1.7.1",
"eslint": "^9.12.0",
"eslint": "^9.13.0",
"eslint-import-resolver-typescript": "^3.6.3",
"eslint-plugin-import": "^2.31.0",
"flora-colossus": "^2.0.0",
Expand Down Expand Up @@ -139,7 +139,7 @@
"dayjs": "^1.11.13",
"decamelize": "^6.0.0",
"decamelize-keys": "^2.0.1",
"echogarden": "^1.8.5",
"echogarden": "^1.8.7",
"electron-context-menu": "^4.0.4",
"electron-log": "^5.2.0",
"electron-settings": "^4.0.4",
Expand All @@ -149,7 +149,7 @@
"fs-extra": "^11.2.0",
"html-to-text": "^9.0.5",
"https-proxy-agent": "^7.0.5",
"i18next": "^23.16.0",
"i18next": "^23.16.1",
"intl-tel-input": "^24.6.0",
"js-md5": "^0.8.3",
"langchain": "^0.3.2",
Expand All @@ -160,17 +160,17 @@
"microsoft-cognitiveservices-speech-sdk": "^1.41.0",
"mustache": "^4.2.0",
"next-themes": "^0.3.0",
"openai": "^4.67.3",
"openai": "^4.68.1",
"pitchfinder": "^2.3.2",
"postcss": "^8.4.47",
"proxy-agent": "^6.4.0",
"react": "^18.3.1",
"react-activity-calendar": "^2.6.2",
"react-activity-calendar": "^2.6.3",
"react-audio-visualize": "^1.2.0",
"react-audio-voice-recorder": "^2.2.0",
"react-dom": "^18.3.1",
"react-frame-component": "^5.2.7",
"react-hook-form": "^7.53.0",
"react-hook-form": "^7.53.1",
"react-hotkeys-hook": "^4.5.1",
"react-i18next": "^15.0.3",
"react-markdown": "^9.0.1",
Expand All @@ -189,7 +189,7 @@
"umzug": "^3.8.2",
"unzipper": "^0.12.3",
"update-electron-app": "^3.0.0",
"wavesurfer.js": "^7.8.6",
"wavesurfer.js": "^7.8.7",
"zod": "^3.23.8",
"zod-to-json-schema": "^3.23.3"
}
Expand Down
26 changes: 24 additions & 2 deletions enjoy/src/renderer/hooks/use-transcriptions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,13 @@ export const useTranscriptions = (media: AudioType | VideoType) => {
items: 10,
});
if (result.transcriptions.length) {
return result.transcriptions[0];
for (const tr of result.transcriptions) {
if (validateTranscription(tr)) {
return tr;
} else {
console.warn(`Invalid transcription: ${tr.id}`);
}
}
} else {
return null;
}
Expand All @@ -115,7 +121,7 @@ export const useTranscriptions = (media: AudioType | VideoType) => {
originalText,
language = learningLanguage,
service = sttEngine,
model,
model: whisperModel,
isolate = false,
} = params || {};
setService(service);
Expand All @@ -138,6 +144,7 @@ export const useTranscriptions = (media: AudioType | VideoType) => {
{
targetId: media.id,
targetType: media.mediaType,
model: whisperModel,
originalText,
language,
service,
Expand Down Expand Up @@ -254,6 +261,21 @@ export const useTranscriptions = (media: AudioType | VideoType) => {
return timeline;
};

const validateTranscription = (transcription: TranscriptionType) => {
if (!transcription) return;

const { timeline, transcript } = transcription.result;
if (!timeline || !transcript) {
return false;
}

if (timeline[0]?.type !== "sentence") {
return false;
}

return true;
};

/*
* find or create transcription
*/
Expand Down
Loading

0 comments on commit d2c32d3

Please sign in to comment.