mirror of
https://gitlab.com/bignutty/labscore.git
synced 2025-06-08 06:03:04 -04:00
mono2: transcribe
This commit is contained in:
parent
b209c257ec
commit
fa50daa2e7
4 changed files with 18 additions and 15 deletions
|
@ -1,7 +1,7 @@
|
|||
const { Constants } = require('detritus-client');
|
||||
const { InteractionCallbackTypes, ApplicationCommandTypes, MessageFlags } = Constants;
|
||||
|
||||
const { transcribeWithSpeakerLabelsObelisk } = require('../../../labscore/api/obelisk');
|
||||
const { AudioTranscribe} = require('../../../labscore/api/obelisk');
|
||||
|
||||
const { createEmbed } = require('../../../labscore/utils/embed');
|
||||
const { codeblock } = require('../../../labscore/utils/markdown');
|
||||
|
@ -34,26 +34,20 @@ module.exports = {
|
|||
flags: MessageFlags.EPHEMERAL
|
||||
})
|
||||
|
||||
const recog = await transcribeWithSpeakerLabelsObelisk(context, message.attachments.first().url)
|
||||
const recog = await AudioTranscribe(context, message.attachments.first().url)
|
||||
|
||||
return editOrReply(context, {
|
||||
embeds: [createEmbed("default", context, {
|
||||
description: codeblock("md", [ recog.response.body.transcription.substr(0,3900) ]),
|
||||
description: codeblock("md", [ recog.response.body.transcript.substr(0,3900) ]),
|
||||
footer: {
|
||||
iconUrl: STATICS.google,
|
||||
text: `Google Cloud • Confidence: ${(recog.response.body.confidence* 100).toFixed(1)}% • ${context.application.name}`
|
||||
text: `Google Speech to Text • ${context.application.name}`
|
||||
}
|
||||
})],
|
||||
flags: MessageFlags.EPHEMERAL
|
||||
})
|
||||
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
if(e.response?.body?.status && e.response.body.status == 2) return editOrReply(context, {
|
||||
embeds: [createEmbed("warning", context, e.response.body.message)],
|
||||
flags: MessageFlags.EPHEMERAL
|
||||
})
|
||||
|
||||
return editOrReply(context, {
|
||||
embeds: [createEmbed("error", context, "Unable to transcribe message.")],
|
||||
flags: MessageFlags.EPHEMERAL
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
const { createEmbed } = require('../../../labscore/utils/embed')
|
||||
const { editOrReply } = require('../../../labscore/utils/message')
|
||||
|
||||
const { transcribeWithSpeakerLabelsObelisk } = require('../../../labscore/api/obelisk');
|
||||
const { AudioTranscribe} = require('../../../labscore/api/obelisk');
|
||||
|
||||
const { STATICS } = require('../../../labscore/utils/statics');
|
||||
const { codeblock, icon } = require('../../../labscore/utils/markdown');
|
||||
|
@ -32,19 +32,19 @@ module.exports = {
|
|||
if(!msg.attachments.first()) return editOrReply(context, createEmbed("warning", context, "No voice message found."))
|
||||
if(!msg.attachments.first().url.split('?')[0].endsWith('voice-message.ogg')) return editOrReply(context, createEmbed("warning", context, "No voice message found."))
|
||||
|
||||
const recog = await transcribeWithSpeakerLabelsObelisk(context, msg.attachments.first().url)
|
||||
const recog = await AudioTranscribe(context, msg.attachments.first().url)
|
||||
|
||||
return editOrReply(context, createEmbed("default", context, {
|
||||
description: codeblock("md", [ recog.response.body.transcription ]),
|
||||
description: codeblock("md", [ recog.response.body.transcript ]),
|
||||
footer: {
|
||||
iconUrl: STATICS.google,
|
||||
text: `Google Cloud • Confidence: ${(recog.response.body.confidence* 100).toFixed(1)}% • ${context.application.name}`
|
||||
text: `Google Speech to Text • ${context.application.name}`
|
||||
}
|
||||
}))
|
||||
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
if(e.response?.body?.status && e.response.body.status == 2) return editOrReply(context, createEmbed("warning", context, e.response.body.message))
|
||||
if(e.response?.body?.error) return editOrReply(context, createEmbed("warning", context, e.response.body.error.message))
|
||||
return editOrReply(context, createEmbed("error", context, `Unable to transcribe audio (too long?).`))
|
||||
}
|
||||
},
|
||||
|
|
|
@ -7,6 +7,8 @@ const ObeliskApi = Object.freeze({
|
|||
HOST: ObeliskHosts.prod,
|
||||
|
||||
// monolith2
|
||||
AUDIO_TRANSCRIBE: "/audio/v1/transcribe",
|
||||
|
||||
LLM_PRIVATE_BARD: "/llm/v1/_private:bard",
|
||||
LLM_MODELS_GENERATE: "/llm/v1/generate",
|
||||
|
||||
|
|
|
@ -40,6 +40,13 @@ async function request(path, type, headers, args, host) {
|
|||
}
|
||||
|
||||
// monolith2
|
||||
module.exports.AudioTranscribe = async function(context, url){
|
||||
return await request(ObeliskApi.AUDIO_TRANSCRIBE, "POST", {}, {
|
||||
url,
|
||||
type: "VOICE_MESSAGE"
|
||||
})
|
||||
}
|
||||
|
||||
module.exports.LlmPrivateBard = async function(context, prompt){
|
||||
return await request(ObeliskApi.LLM_PRIVATE_BARD, "POST", {}, {
|
||||
prompt
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue