Fixes to get voice working properly, not fully confident it'll work under pressure but it's done well in small tests
This commit is contained in:
@@ -169,11 +169,11 @@ def mix_audio_with_ffmpeg(files: list[TranscriptableFile], media_folder_path: st
|
||||
|
||||
output_file_name = Path(
|
||||
media_folder_path,
|
||||
call_id,
|
||||
str(call_id),
|
||||
"output.mp3" if is_final_pass else "intermediate-" + "".join(random.choices(string.ascii_uppercase + string.digits, k=10)) + ".mp3"
|
||||
)
|
||||
|
||||
command_list.append(output_file_name)
|
||||
command_list.append(str(output_file_name))
|
||||
|
||||
# TODO shell = True isn't great, I don't remember the reason why it has to be this way
|
||||
# I *think* it had something to do with me not using ffmpeg's absolute path
|
||||
|
||||
@@ -2,7 +2,7 @@ import json
|
||||
import os
|
||||
import copy
|
||||
from pathlib import Path
|
||||
from datetime import datetime
|
||||
from datetime import datetime, timezone
|
||||
from breadbot_common import SQLite, MySQL, TranscriptableFile, mix_audio_with_ffmpeg
|
||||
from txtai.pipeline import Transcription
|
||||
|
||||
@@ -36,20 +36,25 @@ transcriber = Transcription("openai/whisper-base")
|
||||
for call in calls_needing_work[1]:
|
||||
all_files = os.listdir(Path(
|
||||
config_json["media_voice_folder"],
|
||||
call[0]
|
||||
str(call[0])
|
||||
))
|
||||
|
||||
transcriptable_files = []
|
||||
|
||||
for file in all_files:
|
||||
print(file)
|
||||
file_name_no_extension = file.split('.')[0]
|
||||
timestamp = int(file_name_no_extension.split('-')[0])
|
||||
user_snowflake = file_name_no_extension.split('-')[1]
|
||||
file_stamp_as_datetime = datetime.fromtimestamp(timestamp / 1000)
|
||||
time_diff = file_stamp_as_datetime - call[1]
|
||||
file_stamp_as_datetime = datetime.fromtimestamp(timestamp / 1000, timezone.utc)
|
||||
print(file_stamp_as_datetime)
|
||||
print(type(call[1]))
|
||||
print(call[1])
|
||||
time_diff = file_stamp_as_datetime - datetime.fromisoformat(call[1] + 'Z')
|
||||
print(time_diff)
|
||||
|
||||
transcriptable_files.append(TranscriptableFile(
|
||||
file_path = file,
|
||||
file_path = str(Path(config_json["media_voice_folder"], str(call[0]), file)),
|
||||
real_date = file_stamp_as_datetime,
|
||||
milliseconds_from_start = int((time_diff.seconds * 1000) + (time_diff.microseconds / 1000)),
|
||||
user_snowflake = user_snowflake
|
||||
@@ -60,6 +65,11 @@ for call in calls_needing_work[1]:
|
||||
# TODO Possibly RAM abusive solution to wanting to keep the original list around
|
||||
ffmpeg_files = copy.deepcopy(transcriptable_files)
|
||||
|
||||
for file in ffmpeg_files:
|
||||
print(file.file_path)
|
||||
print(file.real_date)
|
||||
print(file.milliseconds_from_start)
|
||||
|
||||
# TODO Error handling for all ffmpeg operations
|
||||
while len(ffmpeg_files) > MAX_FILES_PER_CYCLE:
|
||||
ffmpeg_files = [
|
||||
@@ -84,9 +94,9 @@ for call in calls_needing_work[1]:
|
||||
"compare": "="
|
||||
}])
|
||||
|
||||
for file in os.listdir(Path(config_json["media_voice_folder"], call[0])):
|
||||
for file in os.listdir(Path(config_json["media_voice_folder"], str(call[0]))):
|
||||
if file.startswith("intermediate"):
|
||||
os.remove(Path(config_json["media_voice_folder"], call[0], file))
|
||||
os.remove(Path(config_json["media_voice_folder"], str(call[0]), file))
|
||||
|
||||
for file in transcriptable_files:
|
||||
text = transcriber(file.file_path)
|
||||
|
||||
@@ -22,6 +22,7 @@ import { DBCallTranscriptions } from "./utilties/storage/entities/DBCallTranscri
|
||||
import { DBCallUsers } from "./utilties/storage/entities/DBCallUsers"
|
||||
import { DBMessageRegex } from "./utilties/storage/entities/DBMessageRegex"
|
||||
import { DBMessageRegexMatches } from "./utilties/storage/entities/DBMessageRegexMatches"
|
||||
import { setupVoice } from "./utilties/events/voice"
|
||||
|
||||
console.log(__dirname + path.sep + "utilities" + path.sep + "storage" + path.sep + "entities" + path.sep + "*.ts")
|
||||
|
||||
@@ -68,6 +69,8 @@ client.once(Events.ClientReady, async () => {
|
||||
const maRepo = dataSource.getRepository(DBMessageAttachments)
|
||||
const regexesRepo = dataSource.getRepository(DBMessageRegex)
|
||||
const matchesRepo = dataSource.getRepository(DBMessageRegexMatches)
|
||||
const callRepo = dataSource.getRepository(DBCall)
|
||||
const callUserRepo = dataSource.getRepository(DBCallUsers)
|
||||
|
||||
client.guilds.cache.forEach(async (guild: Guild) => {
|
||||
const server: DBServer | null = await insertGuild(serverRepo, guild)
|
||||
@@ -116,7 +119,8 @@ client.once(Events.ClientReady, async () => {
|
||||
|
||||
setupRoleCapture(client, serverRepo, roleRepo)
|
||||
setupMessageCapture(client, serverRepo, channelRepo, userRepo, messageRepo, mccRepo, maRepo, regexesRepo, matchesRepo)
|
||||
|
||||
setupVoice(client, callRepo, channelRepo, userRepo, callUserRepo)
|
||||
|
||||
console.log("Breadbot is Ready")
|
||||
})
|
||||
|
||||
|
||||
@@ -40,7 +40,9 @@ export async function returnOrCreateNewCallID(db: Repository<DBCall>, channel: V
|
||||
export async function setCallEndTime(db: Repository<DBCall>, channel: VoiceBasedChannel) : Promise<DBCall | null> {
|
||||
const call: DBCall | null = await db.findOne({
|
||||
"where": {
|
||||
channel: channel,
|
||||
channel: {
|
||||
channel_snowflake: channel.id
|
||||
},
|
||||
call_end_time: IsNull()
|
||||
}
|
||||
})
|
||||
|
||||
@@ -25,9 +25,11 @@ export function setupVoice(client: Client, callDB: Repository<DBCall>, channelDB
|
||||
|
||||
let existingCallID : number | undefined = await getExistingCallID(callDB, newState.channel)
|
||||
|
||||
console.log(`Call ID Pre Existing Call Check: ${existingCallID}`)
|
||||
|
||||
if (existingCallID === undefined) {
|
||||
existingCallID = await returnOrCreateNewCallID(callDB, newState.channel)
|
||||
|
||||
console.log(`Call does not exist new callID value: ${existingCallID}`)
|
||||
mkdirSync(config.MEDIA_VOICE_FOLDER + path.sep + existingCallID, {recursive: true})
|
||||
|
||||
// TODO NULL armor here is probably just going to blow up the call to joinVoiceChannel with no error catching
|
||||
@@ -99,6 +101,13 @@ export function setupVoice(client: Client, callDB: Repository<DBCall>, channelDB
|
||||
return // If the user is breadbot, ignore and exit
|
||||
}
|
||||
|
||||
const connection = getVoiceConnection(oldState.guild.id)
|
||||
|
||||
if(oldState !== null && oldState.member !== null && connection?.receiver.subscriptions.has(oldState.member.id)) {
|
||||
console.log(`Remove receiver subscription ${connection.receiver.subscriptions.delete(oldState.member.id)}`)
|
||||
|
||||
}
|
||||
|
||||
const existingCall : number | undefined = await getExistingCallID(callDB, oldState.channel)
|
||||
|
||||
if (existingCall !== undefined && oldState.member) {
|
||||
@@ -107,12 +116,11 @@ export function setupVoice(client: Client, callDB: Repository<DBCall>, channelDB
|
||||
const usersInCall: number = await numberOfUsersInCall(callUserDB, existingCall)
|
||||
|
||||
if (usersInCall == 0) {
|
||||
const connection = getVoiceConnection(oldState.guild.id)
|
||||
connection?.disconnect()
|
||||
connection?.destroy()
|
||||
|
||||
await setCallEndTime(callDB, oldState.channel)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user