Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: type error fix search for '_text' using in operator not compatible #12

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix: type error fix search for '_text' using in operator not compatible
EchoKuroneko committed Sep 18, 2024
commit d91b1e1bab7b91fb57a2a76c7b64cd984a40c204
21 changes: 16 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
@@ -397,11 +397,22 @@ async function transcribe_witai(buffer) {
witAI_lastcallTS = Math.floor(new Date());
console.log(output)
stream.destroy()
if (output && '_text' in output && output._text.length)
return output._text
if (output && 'text' in output && output.text.length)
return output.text
return output;
let cleanOutput = output.replace(/\r/g, ",").replace(/\n/g, "");
cleanOutput = `[${cleanOutput}]`;
const finalValidOutput = JSON.parse(cleanOutput);
if (finalValidOutput){
for (const obj of finalValidOutput) {
if (obj && obj.type === "FINAL_TRANSCRIPTION") {
if (Object.prototype.hasOwnProperty(obj, "_text") && obj._text.length) {
return obj._text;
}
if (obj.hasOwnProperty("text") && obj.text.length) {
return obj.text;
}
}
}
}
return null;
} catch (e) { console.log('transcribe_witai 851:' + e); console.log(e) }
}