Cleanup and docs
Signed-off-by: Aron Heinecke <aron.heinecke@t-online.de>
This commit is contained in:
parent
a9460dca13
commit
ce4d14c830
4 changed files with 14 additions and 19 deletions
12
README.md
12
README.md
|
@ -7,14 +7,22 @@ This software is in an MVP status, use at your own risk, like always.
|
||||||
## Building
|
## Building
|
||||||
get [rust](https://rust-lang.org) compiler with cargo
|
get [rust](https://rust-lang.org) compiler with cargo
|
||||||
|
|
||||||
`cargo build --release`
|
Then run `cargo build --release`
|
||||||
.exe/elf is inside target/release/
|
.exe/elf is inside target/release/
|
||||||
|
You can also run `cargo run --release` instead to directly build & execute the resulting binary.
|
||||||
|
|
||||||
## Starting
|
## Starting
|
||||||
Setup your credentials inside .credentials.toml by copying credentials.example.toml
|
Setup your credentials inside .credentials.toml by copying credentials.example.toml
|
||||||
|
|
||||||
|
Then join a voice channel in discord, type ~join in a text channel the bot can access. The teamspeak side should already be connected based on your config.
|
||||||
|
|
||||||
Then join a voice channel, type ~join in a text channel the bot can access.
|
## Debugging
|
||||||
|
|
||||||
|
To enable backtrace you can set the `RUST_BACKTRACE` environment variable like so:
|
||||||
|
On linux run with `RUST_BACKTRACE=1` (so `RUST_BACKTRACE=1 cargo run --release`)
|
||||||
|
On windows execute `$Env:RUST_BACKTRACE='1'` in your powershell (I recommend windows terminal). Then run the binary from there, see above.
|
||||||
|
|
||||||
|
Logging can be controlled via `RUST_LOG=<value>` environment variable with `<value>` being one of error, warn, info, debug, trace. See above for setting it.
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,6 @@ use audiopus::coder::Decoder;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use serenity::prelude::{Mentionable, Mutex};
|
use serenity::prelude::{Mentionable, Mutex};
|
||||||
|
|
||||||
use slog::error;
|
|
||||||
// This trait adds the `register_songbird` and `register_songbird_with` methods
|
// This trait adds the `register_songbird` and `register_songbird_with` methods
|
||||||
// to the client builder below, making it easy to install this voice client.
|
// to the client builder below, making it easy to install this voice client.
|
||||||
// The voice client can be retrieved in any command using `songbird::get(ctx).await`.
|
// The voice client can be retrieved in any command using `songbird::get(ctx).await`.
|
||||||
|
@ -37,9 +36,8 @@ use songbird::{
|
||||||
EventContext,
|
EventContext,
|
||||||
EventHandler as VoiceEventHandler,
|
EventHandler as VoiceEventHandler,
|
||||||
};
|
};
|
||||||
use tsproto_packets::packets::{Direction, InAudioBuf};
|
|
||||||
|
|
||||||
use crate::{I16_CONVERSION_DIVIDER, ListenerHolder};
|
use crate::ListenerHolder;
|
||||||
|
|
||||||
pub(crate) struct Handler;
|
pub(crate) struct Handler;
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,6 @@ use audiopus::coder::Decoder;
|
||||||
use audiopus::{packet, Channels, SampleRate};
|
use audiopus::{packet, Channels, SampleRate};
|
||||||
use slog::{Logger, debug, info, o, trace, warn};
|
use slog::{Logger, debug, info, o, trace, warn};
|
||||||
use tsclientlib::audio::Error;
|
use tsclientlib::audio::Error;
|
||||||
use tsproto_packets::packets::{AudioData, CodecType, InAudioBuf};
|
|
||||||
|
|
||||||
use crate::ClientId;
|
use crate::ClientId;
|
||||||
|
|
||||||
|
@ -169,9 +168,6 @@ impl AudioQueue {
|
||||||
Ok(res)
|
Ok(res)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_decoder(&self) -> &Decoder { &self.decoder }
|
|
||||||
pub fn is_whispering(&self) -> bool { self.whispering }
|
|
||||||
|
|
||||||
/// Size is in samples.
|
/// Size is in samples.
|
||||||
fn add_buffer_size(&mut self, size: usize) {
|
fn add_buffer_size(&mut self, size: usize) {
|
||||||
if let Ok(size) = (size / USUAL_FRAME_SIZE).try_into() {
|
if let Ok(size) = (size / USUAL_FRAME_SIZE).try_into() {
|
||||||
|
@ -418,9 +414,6 @@ impl<Id: Clone + Debug + Eq + Hash + PartialEq> AudioHandler<Id> {
|
||||||
/// Delete all queues
|
/// Delete all queues
|
||||||
pub fn reset(&mut self) { self.queues.clear(); }
|
pub fn reset(&mut self) { self.queues.clear(); }
|
||||||
|
|
||||||
pub fn get_queues(&self) -> &HashMap<Id, AudioQueue> { &self.queues }
|
|
||||||
pub fn get_mut_queues(&mut self) -> &mut HashMap<Id, AudioQueue> { &mut self.queues }
|
|
||||||
|
|
||||||
/// `buf` is not cleared before filling it.
|
/// `buf` is not cleared before filling it.
|
||||||
///
|
///
|
||||||
/// Returns the clients that are not talking anymore.
|
/// Returns the clients that are not talking anymore.
|
||||||
|
|
10
src/main.rs
10
src/main.rs
|
@ -1,4 +1,4 @@
|
||||||
use std::{collections::HashMap, io::Read, mem::size_of, sync::Arc, time::Duration};
|
use std::{io::Read, mem::size_of, sync::Arc, time::Duration};
|
||||||
use byte_slice_cast::AsByteSlice;
|
use byte_slice_cast::AsByteSlice;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use tsclientlib::{ClientId, Connection, DisconnectOptions, Identity, StreamItem};
|
use tsclientlib::{ClientId, Connection, DisconnectOptions, Identity, StreamItem};
|
||||||
|
@ -96,10 +96,6 @@ const TICK_TIME: u64 = 20;
|
||||||
const FRAME_SIZE_MS: usize = 20;
|
const FRAME_SIZE_MS: usize = 20;
|
||||||
const SAMPLE_RATE: usize = 48000;
|
const SAMPLE_RATE: usize = 48000;
|
||||||
const STEREO_20MS: usize = SAMPLE_RATE * 2 * FRAME_SIZE_MS / 1000;
|
const STEREO_20MS: usize = SAMPLE_RATE * 2 * FRAME_SIZE_MS / 1000;
|
||||||
// const STEREO_20MS_FLOAT: usize = SAMPLE_RATE / 20;
|
|
||||||
/// See http://blog.bjornroche.com/2009/12/int-float-int-its-jungle-out-there.html
|
|
||||||
/// We use i16::MIN here, which is 0x8000
|
|
||||||
const I16_CONVERSION_DIVIDER: f32 = 0x8000 as f32;
|
|
||||||
/// The maximum size of an opus frame is 1275 as from RFC6716.
|
/// The maximum size of an opus frame is 1275 as from RFC6716.
|
||||||
const MAX_OPUS_FRAME_SIZE: usize = 1275;
|
const MAX_OPUS_FRAME_SIZE: usize = 1275;
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
|
@ -256,12 +252,12 @@ async fn process_discord_audio(voice_buffer: &AudioBufferDiscord, encoder: &Arc<
|
||||||
// buffer_map = std::mem::replace(&mut *lock, HashMap::new());
|
// buffer_map = std::mem::replace(&mut *lock, HashMap::new());
|
||||||
// }
|
// }
|
||||||
|
|
||||||
let mut data = [0.0; 1920];
|
let mut data = [0.0; STEREO_20MS];
|
||||||
{
|
{
|
||||||
let mut lock = voice_buffer.lock().await;
|
let mut lock = voice_buffer.lock().await;
|
||||||
lock.fill_buffer(&mut data);
|
lock.fill_buffer(&mut data);
|
||||||
}
|
}
|
||||||
let mut encoded = [0; 1920];
|
let mut encoded = [0; MAX_OPUS_FRAME_SIZE];
|
||||||
let encoder_c = encoder.clone();
|
let encoder_c = encoder.clone();
|
||||||
// don't block the async runtime
|
// don't block the async runtime
|
||||||
let res = task::spawn_blocking(move || {
|
let res = task::spawn_blocking(move || {
|
||||||
|
|
Loading…
Reference in a new issue