Skip to content

Commit

Permalink
use whisper
Browse files Browse the repository at this point in the history
  • Loading branch information
lluisd committed Nov 5, 2024
1 parent 0d5a7e7 commit aac50dc
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 1 deletion.
1 change: 1 addition & 0 deletions .github/workflows/main_twitch-mz-bot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ jobs:
envkey_OPENAI_MONGODB_URI: ${{ secrets.OPENAI_MONGODB_URI }}
envkey_TWITCH_EVENTSUB_SECRET: ${{ secrets.TWITCH_EVENTSUB_SECRET }}
envkey_TWITCH_HOSTNAME: ${{ secrets.TWITCH_HOSTNAME }}
envkey_WHISPER_ENDPOINT: ${{ secrets.WHISPER_ENDPOINT }}
- name: Set up Node.js version
uses: actions/setup-node@v4
with:
Expand Down
3 changes: 3 additions & 0 deletions config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,8 @@ module.exports = {
apiVersion: process.env.AZURE_OPENAI_API_VERSION,
database: process.env.OPENAI_MONGODB_URI,
vectorStoreId: process.env.AZURE_OPENAI_VECTOR_STORE_ID
},
whisper: {
endpoint: process.env.WHISPER_ENDPOINT,
}
}
13 changes: 13 additions & 0 deletions lib/eventSub.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const {EventSubMiddleware} = require("@twurple/eventsub-http");
const config = require("../config");
const broadcasterApiClient = require('../broadcasterApiClient')
const TwitchService = require("../services/twitch");
const WhisperService = require("../services/whisper");

class EventSub {
constructor() {}
Expand Down Expand Up @@ -79,6 +80,18 @@ class EventSub {
console.log(`Poll ${event.title} has started!`);
this.bot.say(`#${config.twitch.channels}`, `Encuesta iniciada: ${event.title}, vota!`)
})

this.middleware.onStreamOnline(channelId, async event => {
console.log(`Stream ${event.broadcasterDisplayName} has started!`);
await WhisperService.start()
this.bot.say(`#${config.twitch.channels}`, `online`)
})

this.middleware.onStreamOffline(channelId, async event => {
console.log(`Stream ${event.broadcasterDisplayName} has ended!`);
await WhisperService.stop()
this.bot.say(`#${config.twitch.channels}`, `offline`)
})
}
}

Expand Down
9 changes: 8 additions & 1 deletion models/channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,15 @@ const ChannelSchema = new Schema({
activeSpot: {
type: Number,
required: false
},
audioFile: {
type: String,
required: false
},
audioPID: {
type: Number,
required: false
}

})

module.exports = mongoose.model('channel', ChannelSchema, 'channels')
50 changes: 50 additions & 0 deletions services/whisper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
const dbManager = require('../helpers/dbmanager')
const config = require("../config");

async function start () {
let result
let options = await _getHeaders()
const endpoint = config.whisper.endpoint + '/start/' + config.twitch.channels

try {
const response = await fetch(endpoint, options)
result = await response.json()
dbManager.updateChannel(config.twitch.channels, { audioFile: result.filename, audioPID: result.pid })
} catch (e) {
console.log(e)
result = null
}

return result
}

async function stop () {
let result
let options = await _getHeaders()
const endpoint = config.whisper.endpoint + '/stop'

try {
const response = await fetch(endpoint, options)
result = await response.json()
dbManager.updateChannel(config.twitch.channels, { audioFile: null, audioPID: null })
} catch (e) {
console.log(e)
result = null
}

return result
}

async function _getHeaders () {
return {
headers: {
'accept': 'application/json',
'Content-Type': 'application/json'
}
}
}

module.exports = {
start,
stop
}

0 comments on commit aac50dc

Please sign in to comment.