This repository was archived by the owner on Jun 3, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Meeting protocol #236
Draft
cyklon73
wants to merge
19
commits into
SlimeCloud:master
Choose a base branch
from
cyklon73:meeting-protocol
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Meeting protocol #236
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
be3fbb1
moved MeetingConfig in meeting package
cyklon73 e1cf9d9
moved TeamMeeting in meeting package
cyklon73 ad02c03
implemented AudioReceiver to receive audio for every user
cyklon73 d416c27
implemented meeting recording and test commands
cyklon73 bbaddce
fix spelling
cyklon73 ca6838c
added PicoVoiceAI dependency
cyklon73 b0c1283
added german leopard model
cyklon73 2322bdd
added picovoice api key
cyklon73 94a712d
initialize MeetingProtocol
cyklon73 33160b8
process meeting wav files to txt transcript
cyklon73 587e1aa
replace getList with Map#computeIfAbsent
cyklon73 0cd1ae7
changed getUsers return type to Set
cyklon73 f3a8f58
fixed model path
cyklon73 ee64a36
implemented Meeting Command
cyklon73 7362386
implemented Meeting Protocol Start command
cyklon73 8511cf3
implemented Meeting Protocol Stop command
cyklon73 90bf931
moved start and stop command to Meeting Command as Subcommand
cyklon73 6f57766
Merge remote-tracking branch 'main/master' into meeting-protocol
cyklon73 65bd784
register MeetingCommand
cyklon73 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...imeball/features/staff/MeetingConfig.java → ...features/staff/meeting/MeetingConfig.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...slimeball/features/staff/TeamMeeting.java → ...l/features/staff/meeting/TeamMeeting.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
src/main/java/de/slimecloud/slimeball/features/staff/meeting/commands/MeetingCommand.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| package de.slimecloud.slimeball.features.staff.meeting.commands; | ||
|
|
||
| import de.mineking.discordutils.commands.ApplicationCommand; | ||
| import de.mineking.discordutils.commands.Command; | ||
| import de.mineking.discordutils.commands.Setup; | ||
| import de.mineking.discordutils.commands.condition.IRegistrationCondition; | ||
| import de.mineking.discordutils.commands.condition.Scope; | ||
| import de.mineking.discordutils.commands.context.ICommandContext; | ||
| import de.mineking.discordutils.list.ListManager; | ||
| import de.slimecloud.slimeball.config.GuildConfig; | ||
| import de.slimecloud.slimeball.features.staff.meeting.protocol.commands.MeetingProtocolStartCommand; | ||
| import de.slimecloud.slimeball.features.staff.meeting.protocol.commands.MeetingProtocolStopCommand; | ||
| import de.slimecloud.slimeball.main.CommandPermission; | ||
| import de.slimecloud.slimeball.main.SlimeBot; | ||
| import org.jetbrains.annotations.NotNull; | ||
|
|
||
| @ApplicationCommand(name = "meeting", description = "Verwalte Team Meetings", scope = Scope.GUILD) | ||
| public class MeetingCommand { | ||
|
|
||
| public final CommandPermission permission = CommandPermission.TEAM; | ||
| public final IRegistrationCondition<ICommandContext> condition = (manager, guild, cache) -> cache.<GuildConfig>getState("config").getMeeting().isPresent(); | ||
|
|
||
| @Setup | ||
| public static void setup(@NotNull SlimeBot bot, @NotNull Command<ICommandContext> command, @NotNull ListManager<ICommandContext> manager) { | ||
| command.addSubcommand(MeetingProtocolStartCommand.class); | ||
| command.addSubcommand(MeetingProtocolStopCommand.class); | ||
| } | ||
|
|
||
| } |
47 changes: 47 additions & 0 deletions
47
src/main/java/de/slimecloud/slimeball/features/staff/meeting/protocol/AudioReceiver.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| package de.slimecloud.slimeball.features.staff.meeting.protocol; | ||
|
|
||
| import net.dv8tion.jda.api.audio.AudioReceiveHandler; | ||
| import net.dv8tion.jda.api.audio.UserAudio; | ||
|
|
||
| import javax.sound.sampled.AudioInputStream; | ||
| import java.io.ByteArrayInputStream; | ||
| import java.util.*; | ||
|
|
||
| public class AudioReceiver implements AudioReceiveHandler | ||
| { | ||
| private static final double VOLUME = 1.0; | ||
| private final Map<Long, List<byte[]>> received = new LinkedHashMap<>(); | ||
|
|
||
| @Override | ||
| public boolean canReceiveUser() { | ||
| return true; | ||
| } | ||
|
|
||
| @Override | ||
| public void handleUserAudio(UserAudio userAudio) { | ||
| received.computeIfAbsent(userAudio.getUser().getIdLong(), id -> new LinkedList<>()).add(userAudio.getAudioData(VOLUME)); | ||
| } | ||
|
|
||
| public Set<Long> getUsers() { | ||
| return received.keySet(); | ||
| } | ||
|
|
||
| public byte[] getBytes(Long id) { | ||
| int size = 0; | ||
| for (byte[] bytes : received.get(id)) size += bytes.length; | ||
| byte[] data = new byte[size]; | ||
| int i = 0; | ||
| for (byte[] bytes : received.get(id)) { | ||
| for (byte b : bytes) { | ||
| data[i++] = b; | ||
| } | ||
| } | ||
| return data; | ||
| } | ||
|
|
||
| public AudioInputStream getAudioStream(Long id) { | ||
| byte[] data = getBytes(id); | ||
| return new AudioInputStream(new ByteArrayInputStream(data), OUTPUT_FORMAT, data.length); | ||
| } | ||
|
|
||
| } |
107 changes: 107 additions & 0 deletions
107
src/main/java/de/slimecloud/slimeball/features/staff/meeting/protocol/MeetingProtocol.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| package de.slimecloud.slimeball.features.staff.meeting.protocol; | ||
|
|
||
| import ai.picovoice.leopard.Leopard; | ||
| import ai.picovoice.leopard.LeopardException; | ||
| import ai.picovoice.leopard.LeopardTranscript; | ||
| import de.mineking.discordutils.commands.ApplicationCommand; | ||
| import de.mineking.discordutils.commands.ApplicationCommandMethod; | ||
| import de.slimecloud.slimeball.main.SlimeBot; | ||
| import lombok.Getter; | ||
| import lombok.SneakyThrows; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import net.dv8tion.jda.api.JDA; | ||
| import net.dv8tion.jda.api.entities.Guild; | ||
| import net.dv8tion.jda.api.entities.GuildVoiceState; | ||
| import net.dv8tion.jda.api.entities.User; | ||
| import net.dv8tion.jda.api.entities.channel.concrete.VoiceChannel; | ||
| import net.dv8tion.jda.api.entities.channel.unions.AudioChannelUnion; | ||
| import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; | ||
| import net.dv8tion.jda.api.managers.AudioManager; | ||
| import org.jetbrains.annotations.NotNull; | ||
|
|
||
| import javax.sound.sampled.AudioFileFormat; | ||
| import javax.sound.sampled.AudioInputStream; | ||
| import javax.sound.sampled.AudioSystem; | ||
| import java.io.File; | ||
| import java.io.FileOutputStream; | ||
| import java.io.IOException; | ||
| import java.net.URL; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| @Slf4j | ||
| public class MeetingProtocol { | ||
|
|
||
| private static final File protocolDirectory = new File("protocol"); | ||
|
|
||
| static { | ||
| protocolDirectory.mkdirs(); | ||
| } | ||
|
|
||
| private final String picovoice_access_key; | ||
| private final File leopard_model; | ||
| @Getter | ||
| private AudioReceiver receiver; | ||
|
|
||
| public MeetingProtocol(String picovoice_access_key) { | ||
| this.picovoice_access_key = picovoice_access_key; | ||
| URL url = MeetingProtocol.class.getClassLoader().getResource("leopard_params_de.pv"); | ||
| if (url == null || url.getPath().isBlank()) throw new RuntimeException("Leopard model not found"); | ||
| this.leopard_model = new File(url.getPath()); | ||
| } | ||
|
|
||
| public void start(VoiceChannel vc) { | ||
| receiver = new AudioReceiver(); | ||
| Guild guild = vc.getGuild(); | ||
| AudioManager audioManager = guild.getAudioManager(); | ||
| audioManager.openAudioConnection(vc); | ||
| audioManager.setReceivingHandler(receiver); | ||
| } | ||
|
|
||
| @SneakyThrows(LeopardException.class) | ||
| public void stop(Guild guild) { | ||
| JDA jda = guild.getJDA(); | ||
|
|
||
| List<User> users = new ArrayList<>(); | ||
| for (Long id : receiver.getUsers()) users.add(jda.getUserById(id)); | ||
|
|
||
| for (User user : users) { | ||
| try (AudioInputStream ais = receiver.getAudioStream(user.getIdLong())) { | ||
| AudioSystem.write(ais, AudioFileFormat.Type.WAVE, new File(protocolDirectory, String.format("%s.wav", user.getName()))); | ||
| } catch (IOException e) { | ||
| logger.error("failed to save protocol as wav from " + user.getName(), e); | ||
| } | ||
| } | ||
|
|
||
| Leopard leopard = new Leopard.Builder() | ||
| .setAccessKey(picovoice_access_key) | ||
| .setModelPath(leopard_model.getAbsolutePath()) | ||
| .build(); | ||
|
|
||
| for (User user : users) { | ||
| try { | ||
| File file = new File(protocolDirectory, String.format("%s.wav", user.getName())); | ||
| if (!file.exists()) { | ||
| logger.debug("skip user " + user.getName() + " for processing because the " + file.getName() + " file is missing"); | ||
| continue; | ||
| } | ||
| LeopardTranscript transcript = leopard.processFile(file.getAbsolutePath()); | ||
| file.delete(); | ||
|
|
||
| try (FileOutputStream fos = new FileOutputStream(new File(protocolDirectory, user.getName() + ".txt"))) { | ||
| fos.write(transcript.getTranscriptString().getBytes()); | ||
| } catch (IOException e) { | ||
| logger.error("failed to save protocol transcript from " + user.getName(), e); | ||
| } | ||
| } catch (LeopardException e) { | ||
| logger.error("failed to process protocol from " + user.getName(), e); | ||
| } | ||
| } | ||
| leopard.delete(); | ||
|
|
||
| AudioManager audioManager = guild.getAudioManager(); | ||
| audioManager.setReceivingHandler(null); | ||
| audioManager.closeAudioConnection(); | ||
| receiver = null; | ||
| } | ||
| } | ||
27 changes: 27 additions & 0 deletions
27
...cloud/slimeball/features/staff/meeting/protocol/commands/MeetingProtocolStartCommand.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| package de.slimecloud.slimeball.features.staff.meeting.protocol.commands; | ||
|
|
||
| import de.mineking.discordutils.commands.ApplicationCommand; | ||
| import de.mineking.discordutils.commands.ApplicationCommandMethod; | ||
| import de.slimecloud.slimeball.main.SlimeBot; | ||
| import net.dv8tion.jda.api.entities.GuildVoiceState; | ||
| import net.dv8tion.jda.api.entities.channel.unions.AudioChannelUnion; | ||
| import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; | ||
| import org.jetbrains.annotations.NotNull; | ||
|
|
||
| @ApplicationCommand(name = "protocol-start", description = "Startet das Automatische Meeting Protokoll", defer = true) | ||
| public class MeetingProtocolStartCommand { | ||
|
|
||
| @ApplicationCommandMethod | ||
| public void performCommand(@NotNull SlimeBot bot, @NotNull SlashCommandInteractionEvent event) { | ||
| if (bot.getMeetingProtocol().getReceiver () != null) event.getHook().sendMessage("stop meeting recording first").queue(); | ||
| GuildVoiceState state = event.getMember().getVoiceState(); | ||
| if (state != null) { | ||
| AudioChannelUnion union = state.getChannel(); | ||
| if (union != null) { | ||
| bot.getMeetingProtocol().start(union.asVoiceChannel()); | ||
| event.getHook().sendMessage("meeting recording started").queue(); | ||
| } else event.getHook().sendMessage("connect first to a voice channel").queue(); | ||
| } else event.getHook().sendMessage("connect first to a voice channel").queue(); | ||
| } | ||
|
|
||
| } |
19 changes: 19 additions & 0 deletions
19
...ecloud/slimeball/features/staff/meeting/protocol/commands/MeetingProtocolStopCommand.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| package de.slimecloud.slimeball.features.staff.meeting.protocol.commands; | ||
|
|
||
| import de.mineking.discordutils.commands.ApplicationCommand; | ||
| import de.mineking.discordutils.commands.ApplicationCommandMethod; | ||
| import de.slimecloud.slimeball.main.SlimeBot; | ||
| import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; | ||
| import org.jetbrains.annotations.NotNull; | ||
|
|
||
| @ApplicationCommand(name = "protocol-start", description = "Startet das Automatische Meeting Protokoll", defer = true) | ||
| public class MeetingProtocolStopCommand { | ||
|
|
||
| @ApplicationCommandMethod | ||
| public void performCommand(@NotNull SlimeBot bot, @NotNull SlashCommandInteractionEvent event) { | ||
| if (bot.getMeetingProtocol().getReceiver() == null) event.getHook().sendMessage("start meeting recording first").queue(); | ||
| bot.getMeetingProtocol().stop(event.getGuild()); | ||
| event.getHook().sendMessage("meeting recording stopped!").queue(); | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.