Skip to content

Commit

Permalink
文字起こしの精度向上・ワーカー上でゴミファイルが残り続けてしまう不具合を修正
Browse files Browse the repository at this point in the history
  • Loading branch information
tissueMO committed Nov 5, 2024
1 parent ad17127 commit 23e5a79
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
24 changes: 19 additions & 5 deletions extensions/discord/addon/RecordAddon.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,11 @@ class RecordAddon extends Addon {
userName: guild.members.cache.get(userId).displayName,
start: dayjs().tz().format(),
}))
.then(context => this.#enqueueConvertWorker(context));
.then(context => {
if (context) {
this.#enqueueConvertWorker(context);
}
});
}
});

Expand Down Expand Up @@ -309,25 +313,35 @@ class RecordAddon extends Addon {
createWriteStream(pcmFile)
);

context['end'] = dayjs().tz().format();

// ※相槌やノイズのような短い音声は除外
const start = dayjs(context.start);
const end = dayjs(context.end);

if (end.diff(start, 'second') <= 3) {
console.info(`[RecordAddon] キャプチャーキャンセル: User<${userId}> Session<${contextId}>`);
return null;
}

await s3Client.send(new PutObjectCommand({
Bucket: process.env.S3_BUCKET,
Key: `${process.env.S3_PREFIX}${baseName}`,
Body: createReadStream(pcmFile),
}));

await fs.unlink(pcmFile);

console.info(`[RecordAddon] キャプチャー終了: User<${userId}> Session<${contextId}> --> ${pcmFile}`);
return context;

} catch (err) {
console.error(`[RecordAddon] キャプチャー失敗: User<${userId}> Session<${contextId}>`, err);
return null;

} finally {
await fs.unlink(pcmFile);
delete this.#contexts[userId];
}

return context;
}

/**
Expand All @@ -351,7 +365,7 @@ class RecordAddon extends Addon {
* @param {VoiceChannel} channel
* @param {dayjs.Dayjs} start
* @param {dayjs.Dayjs} end
* @returns {string|null}
* @returns {Promise<string|null>}
*/
async #fetchTranscription(channel, start, end) {
const contextIds = await this.#redisClient.zRangeByScore(`${process.env.REDIS_NAMESPACE}:contexts`, start.valueOf(), end.valueOf());
Expand Down
1 change: 1 addition & 0 deletions extensions/discord/worker/ConvertWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class ConvertWorker extends Worker {

// 後片付け
await fs.unlink(srcFile);
await fs.unlink(destFile);

await s3Client.send(new DeleteObjectCommand({
Bucket: process.env.S3_BUCKET,
Expand Down
2 changes: 2 additions & 0 deletions extensions/discord/worker/TranscribeWorker.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const fs = require('fs').promises;
const { default: axios } = require('axios');
const { createWriteStream, createReadStream } = require('fs');
const path = require('path');
Expand Down Expand Up @@ -52,6 +53,7 @@ class TranscribeWorker extends Worker {
});

// 後片付け
await fs.unlink(srcFile);
await s3Client.send(new DeleteObjectCommand({
Bucket: process.env.S3_BUCKET,
Key: `${process.env.S3_PREFIX}${baseName}`,
Expand Down

0 comments on commit 23e5a79

Please sign in to comment.