Commit 274551c0 authored by Jose V. Trigueros's avatar Jose V. Trigueros

Remove Voice Send

parent a79f0963
Pipeline #101463014 passed with stages
in 14 minutes and 17 seconds
......@@ -10,12 +10,12 @@
</scm>
<properties>
<jda.version>4.0.0_70</jda.version>
<jda.version>4.0.0_72</jda.version>
<kotlin.compiler.incremental>true</kotlin.compiler.incremental>
<kotlin.compiler.jvmTarget>11</kotlin.compiler.jvmTarget>
<kotlin.version>1.3.61</kotlin.version>
<main.class>tech.gdragon.App</main.class>
<metrics.version>4.1.1</metrics.version>
<metrics.version>4.1.2</metrics.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<slf4j.version>2.0.0-alpha1</slf4j.version>
</properties>
......
......@@ -16,11 +16,8 @@ import tech.gdragon.db.dao.Channel
import tech.gdragon.db.dao.Guild
import tech.gdragon.db.table.Tables.Guilds
import tech.gdragon.listener.CombinedAudioRecorderHandler
import tech.gdragon.listener.SilenceAudioSendHandler
import java.io.File
import java.io.FileInputStream
import java.util.*
import kotlin.concurrent.schedule
import net.dv8tion.jda.api.entities.Guild as DiscordGuild
object BotUtils {
......@@ -141,15 +138,7 @@ object BotUtils {
} ?: 1.0
val recorder = CombinedAudioRecorderHandler(volume, channel, defaultChannel)
val audioSendHandler = SilenceAudioSendHandler()
// Only send 5 seconds of audio at the beginning of the recording see: https://github.com/DV8FromTheWorld/JDA/issues/653
Timer().schedule(5 * 1000) {
audioSendHandler.canProvide = false
}
audioManager.receivingHandler = recorder
audioManager.sendingHandler = audioSendHandler
recordingStatus(channel.guild.selfMember, true)
sendMessage(defaultChannel, """:red_circle: **Recording audio on <#${channel.id}>**
......
package tech.gdragon
import com.squareup.tape.QueueFile
import de.sciss.jump3r.lowlevel.LameEncoder
import net.dv8tion.jda.api.AccountType
import net.dv8tion.jda.api.JDABuilder
import net.dv8tion.jda.api.audio.AudioReceiveHandler
import net.dv8tion.jda.api.events.guild.voice.GuildVoiceJoinEvent
import net.dv8tion.jda.api.events.guild.voice.GuildVoiceLeaveEvent
import net.dv8tion.jda.api.hooks.ListenerAdapter
import org.apache.commons.io.FileUtils
import org.jetbrains.exposed.sql.*
import org.jetbrains.exposed.sql.transactions.TransactionManager
import org.jetbrains.exposed.sql.transactions.transaction
......@@ -18,6 +21,8 @@ import tech.gdragon.db.dao.Guild
import tech.gdragon.db.initializeDatabase
import tech.gdragon.db.table.Tables
import tech.gdragon.db.table.Tables.Guilds
import tech.gdragon.listener.CombinedAudioRecorderHandler
import java.io.ByteArrayOutputStream
import java.io.File
import java.io.FileOutputStream
import java.sql.Connection
......@@ -128,6 +133,15 @@ fun queue2mp3(qFile: String) {
}
}
fun pcm2mp3(pcm: String) {
val pcmBytes = FileUtils.readFileToByteArray(File(pcm))
val encoder = LameEncoder(AudioReceiveHandler.OUTPUT_FORMAT, 128, LameEncoder.CHANNEL_MODE_AUTO, LameEncoder.QUALITY_HIGHEST, true)
val buffer = ByteArray(pcmBytes.size)
val encodedCount = encoder.encodeBuffer(pcmBytes, 0, pcmBytes.size, buffer)
FileUtils.writeByteArrayToFile(File("$pcm.mp3"), buffer)
}
fun initializeKoin() = startKoin {
printLogger(Level.INFO)
fileProperties("/defaults.properties")
......
package tech.gdragon.listener
import mu.KotlinLogging
import net.dv8tion.jda.api.audio.AudioSendHandler
import java.nio.ByteBuffer
class SilenceAudioSendHandler : AudioSendHandler {
private val logger = KotlinLogging.logger { }
var canProvide = true
set(value) {
logger.debug { "canProvide toggling from $canProvide to $value" }
field = value
}
override fun provide20MsAudio(): ByteBuffer? {
val silence = arrayOf(0xF8.toByte(), 0xFF.toByte(), 0xFE.toByte())
return ByteBuffer.wrap(silence.toByteArray())
}
override fun canProvide(): Boolean {
return canProvide
}
override fun isOpus(): Boolean {
return true
}
}
package tech.gdragon.listener
import mu.KotlinLogging
import net.dv8tion.jda.api.events.channel.voice.VoiceChannelCreateEvent
import net.dv8tion.jda.api.events.channel.voice.VoiceChannelDeleteEvent
import net.dv8tion.jda.api.events.channel.voice.update.VoiceChannelUpdateNameEvent
import net.dv8tion.jda.api.hooks.ListenerAdapter
class VoiceChannelListener : ListenerAdapter() {
private val logger = KotlinLogging.logger {}
override fun onVoiceChannelCreate(event: VoiceChannelCreateEvent) {
logger.debug { "Creating Channel: ${event.channel}" }
super.onVoiceChannelCreate(event)
}
override fun onVoiceChannelDelete(event: VoiceChannelDeleteEvent) {
logger.debug { "Deleting Channel: ${event.channel}" }
super.onVoiceChannelDelete(event)
}
override fun onVoiceChannelUpdateName(event: VoiceChannelUpdateNameEvent) {
logger.debug { "Updating Channel: ${event.channel}" }
super.onVoiceChannelUpdateName(event)
}
}
package tech.gdragon.listener.rx
import io.reactivex.Observable
import net.dv8tion.jda.api.audio.AudioReceiveHandler
import net.dv8tion.jda.api.audio.CombinedAudio
import net.dv8tion.jda.api.audio.UserAudio
import net.dv8tion.jda.api.managers.AudioManager
fun audioReceiveObservable(audioManager: AudioManager): Observable<CombinedAudio> {
return Observable.create { subscriber ->
object : AudioReceiveHandler {
init {
println("init observable")
audioManager.setReceivingHandler(this)
}
override fun canReceiveUser(): Boolean = false
// NOTE: Each segment of audio data is 3840 bytes long
// NOTE: 48KHz 16bit stereo signed BigEndian PCM
override fun handleCombinedAudio(combinedAudio: CombinedAudio) {
if (subscriber.isDisposed) {
println("subscriber.isDisposed = ${subscriber.isDisposed}")
} else {
subscriber.onNext(combinedAudio)
}
}
override fun handleUserAudio(userAudio: UserAudio) {
TODO("Not supported.")
}
override fun canReceiveCombined(): Boolean = true
}
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment