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(
|
output_file_name = Path(
|
||||||
media_folder_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"
|
"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
|
# 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
|
# I *think* it had something to do with me not using ffmpeg's absolute path
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import json
|
|||||||
import os
|
import os
|
||||||
import copy
|
import copy
|
||||||
from pathlib import Path
|
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 breadbot_common import SQLite, MySQL, TranscriptableFile, mix_audio_with_ffmpeg
|
||||||
from txtai.pipeline import Transcription
|
from txtai.pipeline import Transcription
|
||||||
|
|
||||||
@@ -36,20 +36,25 @@ transcriber = Transcription("openai/whisper-base")
|
|||||||
for call in calls_needing_work[1]:
|
for call in calls_needing_work[1]:
|
||||||
all_files = os.listdir(Path(
|
all_files = os.listdir(Path(
|
||||||
config_json["media_voice_folder"],
|
config_json["media_voice_folder"],
|
||||||
call[0]
|
str(call[0])
|
||||||
))
|
))
|
||||||
|
|
||||||
transcriptable_files = []
|
transcriptable_files = []
|
||||||
|
|
||||||
for file in all_files:
|
for file in all_files:
|
||||||
|
print(file)
|
||||||
file_name_no_extension = file.split('.')[0]
|
file_name_no_extension = file.split('.')[0]
|
||||||
timestamp = int(file_name_no_extension.split('-')[0])
|
timestamp = int(file_name_no_extension.split('-')[0])
|
||||||
user_snowflake = file_name_no_extension.split('-')[1]
|
user_snowflake = file_name_no_extension.split('-')[1]
|
||||||
file_stamp_as_datetime = datetime.fromtimestamp(timestamp / 1000)
|
file_stamp_as_datetime = datetime.fromtimestamp(timestamp / 1000, timezone.utc)
|
||||||
time_diff = file_stamp_as_datetime - call[1]
|
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(
|
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,
|
real_date = file_stamp_as_datetime,
|
||||||
milliseconds_from_start = int((time_diff.seconds * 1000) + (time_diff.microseconds / 1000)),
|
milliseconds_from_start = int((time_diff.seconds * 1000) + (time_diff.microseconds / 1000)),
|
||||||
user_snowflake = user_snowflake
|
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
|
# TODO Possibly RAM abusive solution to wanting to keep the original list around
|
||||||
ffmpeg_files = copy.deepcopy(transcriptable_files)
|
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
|
# TODO Error handling for all ffmpeg operations
|
||||||
while len(ffmpeg_files) > MAX_FILES_PER_CYCLE:
|
while len(ffmpeg_files) > MAX_FILES_PER_CYCLE:
|
||||||
ffmpeg_files = [
|
ffmpeg_files = [
|
||||||
@@ -84,9 +94,9 @@ for call in calls_needing_work[1]:
|
|||||||
"compare": "="
|
"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"):
|
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:
|
for file in transcriptable_files:
|
||||||
text = transcriber(file.file_path)
|
text = transcriber(file.file_path)
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import { DBCallTranscriptions } from "./utilties/storage/entities/DBCallTranscri
|
|||||||
import { DBCallUsers } from "./utilties/storage/entities/DBCallUsers"
|
import { DBCallUsers } from "./utilties/storage/entities/DBCallUsers"
|
||||||
import { DBMessageRegex } from "./utilties/storage/entities/DBMessageRegex"
|
import { DBMessageRegex } from "./utilties/storage/entities/DBMessageRegex"
|
||||||
import { DBMessageRegexMatches } from "./utilties/storage/entities/DBMessageRegexMatches"
|
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")
|
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 maRepo = dataSource.getRepository(DBMessageAttachments)
|
||||||
const regexesRepo = dataSource.getRepository(DBMessageRegex)
|
const regexesRepo = dataSource.getRepository(DBMessageRegex)
|
||||||
const matchesRepo = dataSource.getRepository(DBMessageRegexMatches)
|
const matchesRepo = dataSource.getRepository(DBMessageRegexMatches)
|
||||||
|
const callRepo = dataSource.getRepository(DBCall)
|
||||||
|
const callUserRepo = dataSource.getRepository(DBCallUsers)
|
||||||
|
|
||||||
client.guilds.cache.forEach(async (guild: Guild) => {
|
client.guilds.cache.forEach(async (guild: Guild) => {
|
||||||
const server: DBServer | null = await insertGuild(serverRepo, guild)
|
const server: DBServer | null = await insertGuild(serverRepo, guild)
|
||||||
@@ -116,7 +119,8 @@ client.once(Events.ClientReady, async () => {
|
|||||||
|
|
||||||
setupRoleCapture(client, serverRepo, roleRepo)
|
setupRoleCapture(client, serverRepo, roleRepo)
|
||||||
setupMessageCapture(client, serverRepo, channelRepo, userRepo, messageRepo, mccRepo, maRepo, regexesRepo, matchesRepo)
|
setupMessageCapture(client, serverRepo, channelRepo, userRepo, messageRepo, mccRepo, maRepo, regexesRepo, matchesRepo)
|
||||||
|
setupVoice(client, callRepo, channelRepo, userRepo, callUserRepo)
|
||||||
|
|
||||||
console.log("Breadbot is Ready")
|
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> {
|
export async function setCallEndTime(db: Repository<DBCall>, channel: VoiceBasedChannel) : Promise<DBCall | null> {
|
||||||
const call: DBCall | null = await db.findOne({
|
const call: DBCall | null = await db.findOne({
|
||||||
"where": {
|
"where": {
|
||||||
channel: channel,
|
channel: {
|
||||||
|
channel_snowflake: channel.id
|
||||||
|
},
|
||||||
call_end_time: IsNull()
|
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)
|
let existingCallID : number | undefined = await getExistingCallID(callDB, newState.channel)
|
||||||
|
|
||||||
|
console.log(`Call ID Pre Existing Call Check: ${existingCallID}`)
|
||||||
|
|
||||||
if (existingCallID === undefined) {
|
if (existingCallID === undefined) {
|
||||||
existingCallID = await returnOrCreateNewCallID(callDB, newState.channel)
|
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})
|
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
|
// 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
|
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)
|
const existingCall : number | undefined = await getExistingCallID(callDB, oldState.channel)
|
||||||
|
|
||||||
if (existingCall !== undefined && oldState.member) {
|
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)
|
const usersInCall: number = await numberOfUsersInCall(callUserDB, existingCall)
|
||||||
|
|
||||||
if (usersInCall == 0) {
|
if (usersInCall == 0) {
|
||||||
const connection = getVoiceConnection(oldState.guild.id)
|
connection?.destroy()
|
||||||
connection?.disconnect()
|
|
||||||
|
|
||||||
await setCallEndTime(callDB, oldState.channel)
|
await setCallEndTime(callDB, oldState.channel)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user