Use mtf-module-redis
This commit is contained in:
parent
fdf908dc86
commit
6e8c689639
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
[submodule "src/modules/redis"]
|
||||
path = src/modules/redis
|
||||
url = https://gitea.spilum.net/Spilum.Net/mtf-module-redis
|
||||
@ -1,41 +0,0 @@
|
||||
const config = require("../config");
|
||||
const redisConfig = require("../config/redis.config");
|
||||
|
||||
// Redis Connection
|
||||
const Redis = require('redis');
|
||||
const redis = {};
|
||||
|
||||
redis.client = Redis.createClient({
|
||||
url: `redis://default@${redisConfig.HOST}:${redisConfig.PORT}`
|
||||
});
|
||||
|
||||
redis.ensureGroup = async (stream, group) => {
|
||||
try {
|
||||
await redis.client.xGroupCreate(stream, group, "0", {MKSTREAM: true});
|
||||
|
||||
console.log(`Created consumer group: ${group} (${stream})`);
|
||||
} catch (err) {
|
||||
if (err.message.includes('BUSYGROUP')) {
|
||||
console.log(`Consumer group already exists: ${group} (${stream})`);
|
||||
} else {
|
||||
console.error(err);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
redis.sendTranscriptEvent = async (streamKey, device_id, text) => {
|
||||
try {
|
||||
await redis.client.xAdd(streamKey, "*", {
|
||||
text,
|
||||
device_id: device_id,
|
||||
});
|
||||
|
||||
console.log("Transcript added to stream");
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
redis
|
||||
};
|
||||
1
src/modules/redis
Submodule
1
src/modules/redis
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit e41a75e7436a059ab963c5db7b62ca524cacc4e5
|
||||
@ -13,8 +13,7 @@ const wav = require("wav-decoder");
|
||||
const Speaker = require("speaker");
|
||||
const { spawn } = require("child_process");
|
||||
|
||||
const models = require("./models");
|
||||
const redis = models.redis;
|
||||
const {redis} = require('./modules/redis');
|
||||
|
||||
const config = require("./config");
|
||||
const transConfig = require("./config/transcribe.config");
|
||||
@ -148,7 +147,7 @@ async function processor(group, consumer, streamKey) {
|
||||
}
|
||||
|
||||
async function main() {
|
||||
await redis.client.connect().catch(console.error);
|
||||
await redis.connect();
|
||||
await redis.ensureGroup("commands", "assistant");
|
||||
|
||||
await playAudio("Assistant, online.");
|
||||
|
||||
Loading…
Reference in New Issue
Block a user