-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
678e40d
commit c8dc403
Showing
15 changed files
with
102 additions
and
20 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { EVENTS, addKeyword } from "@builderbot/bot"; | ||
import { BaileysProvider } from "@builderbot/provider-baileys"; | ||
import AIClass from "src/services/ai"; | ||
import { processAudio } from "src/utils/process"; | ||
import { welcomeFlow } from "./welcome.flow"; | ||
import mainLayer from "src/layers/main.layer"; | ||
import { handleHistory } from "src/utils/handleHistory"; | ||
|
||
const voiceFlow = addKeyword<BaileysProvider>(EVENTS.VOICE_NOTE) | ||
.addAction(async (_, { flowDynamic }) => { | ||
await flowDynamic(`dame un momento para esucharte...`) | ||
}) | ||
.addAction(async (ctx: any, { provider, extensions, gotoFlow, state }) => { | ||
try{ | ||
const ai = extensions.ai as AIClass | ||
const pathVoice = await provider.saveFile(ctx) | ||
const mp3Path = await processAudio(pathVoice) | ||
const text = await ai.voiceToText(mp3Path) | ||
await handleHistory({ content: text, role: 'user' }, state) | ||
return gotoFlow(welcomeFlow) | ||
}catch(e){ | ||
console.log(`Err`,e)} | ||
}) | ||
.addAction(mainLayer) | ||
|
||
export { voiceFlow } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import ffmpeg from "fluent-ffmpeg"; | ||
import {join} from "path"; | ||
import {tmpdir} from "os"; | ||
import { path as ffmpegPath } from '@ffmpeg-installer/ffmpeg'; | ||
ffmpeg.setFfmpegPath(ffmpegPath); | ||
|
||
const convertOggMp3 = async (inputStream: string, outStream: string) => { | ||
return new Promise((resolve) => { | ||
ffmpeg(inputStream) | ||
.audioQuality(96) | ||
.toFormat("mp3") | ||
.save(outStream) | ||
.on("progress", () => null) | ||
.on("end", () => { | ||
resolve(true); | ||
}); | ||
}); | ||
}; | ||
|
||
/** | ||
* Return mp3 path | ||
*/ | ||
export const processAudio = async (pathOgg: string ) => { | ||
const pathTmpMp3 = join(tmpdir(),`voice-note-${Date.now()}.mp3`); | ||
await convertOggMp3(pathOgg, pathTmpMp3); | ||
return pathTmpMp3 | ||
} |