Voice¶
Warning
Voice may not be able to send any data as of now, this is due to a bug with encoding. If you have your own encoder feel free to use it.
VoiceConnection¶
- asyncchange_speaking_state
- asyncclient_connect
- asyncconnect
- asyncdisconnect
- defidentity
- asynclisten
- asyncresume
- asyncsend_audio_packet
- asyncstop_speaking
- defudp_payload
- asyncupd_connect
- asyncwait_until_connected
- asyncwait_until_ready
- class acord.VoiceConnection(voice_packet: dict, loop: asyncio.events.AbstractEventLoop, client, channel_id, **kwargs)[source]¶
Represents a voice connection between client and a discord voice channel
- channel_id¶
ID of channel
- Type
Snowflake
- guild_id¶
ID of guild
- Type
Snowflake
- async change_speaking_state(flags: int = 1, delay: int = 0) None[source]¶
This function is a coroutine.
Changes the speaking state of the client
- async client_connect() None[source]¶
This function is a coroutine.
Sends a OP 12 payload through the ws.
- async connect(*, v: int = 6) None[source]¶
This function is a coroutine.
Creates a websocket connection to the endpoint provided by discord
- Parameters
v (
int) – Endpoint version
- async disconnect(*, message: bytes = b'') None[source]¶
This function is a coroutine.
Disconnects the voice connection closing both UDP and WS connection, it also terminates the task generated by
VoiceConnection.listen()
- async listen(**kwargs) None[source]¶
Begins to listen for websocket events, to terminate this simply end generated task
- async resume() None[source]¶
This function is a coroutine.
Resumes the websocket connection for the vc, this should rarely be called by the user.
- async send_audio_packet(data: bytes, frames: int, *, has_header: bool = False, sock_flags: int = 0) None[source]¶
This function is a coroutine.
Sends an audio packet to discord
- Parameters
data (
bytes) – Bytes of data to send to discordhas_header (
bool) – Whether the data has an RTC header attached to it. Defaults to False and should only be True if you know what your doing.frames (
int) – Your encoders SAMPLES_PER_FRAME value, used for generating timestampsock_flags (
int) – Additional flags for the UDP socket
- async stop_speaking() None[source]¶
This function is a coroutine.
Shortcut method to
VoiceConnection.change_speaking_state(), tells discord that the client has stopped speaking
- async upd_connect(addr: str, port: int, **kwargs) None[source]¶
This function is a coroutine.
Connects to the UDP port, spawns a new
UDPConnection, which can be accessed by_sock.
UDPConnection¶
- asyncclose
- asyncconnect
- defis_connected
- asyncread
- asyncsendto
- asyncwait_until_connected
- asyncwrite
- class acord.UDPConnection(host, port, loop, client, vc_Ws, conn_id, **kwds)[source]¶
Represents a UDP connection
- loop¶
Loop that is being used
- Type
py:asyncio.AbstractLoopEvent
- vc_Ws¶
Voice Connection using this UDP connection
- Type
- \*\*kwds
Any kwargs for connecting to the socket, type and family are overwritten.
- async connect() None[source]¶
This function is a coroutine.
Connects to the UDP port.
Note
It will attempt to connect to the port 5 times before failing, this will only occur when it fails with codes 121 or 10060.
- async read(*, limit: Optional[int] = None, flags: int = 0) bytes[source]¶
This function is a coroutine.
Reads from the socket stream
- async sendto(data: bytes, addr: tuple) None[source]¶
This function is a coroutine.
Choose to send bytes directly to the provided addr
Transports¶
BaseTransport¶
- class acord.BaseTransport(conn: acord.voice.core.VoiceConnection)[source]¶
Base transport for working with the UDP connection
- Parameters
conn (
VoiceConnection) – Original websocket class when starting voice connectionsock (
UDPConnection) – UDP socket class
- abstract async cleanup() None[source]¶
This function is a coroutine.
Cleans up any cache, if any. Should be implemented by recievers which save last recieved packet, and for writers should reset state of the writer
- abstract async close() None[source]¶
This function is a coroutine.
Closes this transport, leaving UDP connection open!
For recievers this should be set to stop recieving, and for writers to close any files + stop writing.
- async recieve(*, limit: Optional[int] = None, flags: int = - 1, decode: bool = False) Optional[bytes][source]¶
This function is a coroutine.
Reads data from stream, recievers will automatically read and dispatch data from streams. Writers should not implement this method but if needed try implement a reciever
- async send(data: bytes, *, flags: int = 0, c_flags: int = 5, continued: bool = False) None[source]¶
This function is a coroutine.
Sends data through stream, writers must include this method and should make sure each packet has an RTC header. To simplify this mess you should call
VoiceConnection._get_audio_packet.Note
When implementing writers, big files should be handled by you and for sending “complete” payloads, call
VoiceConnection.send_audio_packet.
BasePlayer¶
- class acord.BasePlayer(conn: acord.voice.core.VoiceConnection, data: Union[io.BufferedIOBase, os.PathLike], encoder: Optional[acord.voice.opus.Encoder] = None, **encoder_kwargs)[source]¶
- async cleanup() None[source]¶
This function is a coroutine.
Cleans up any cache, if any. Should be implemented by recievers which save last recieved packet, and for writers should reset state of the writer
- close() None[source]¶
This function is a coroutine.
Closes this transport, leaving UDP connection open!
For recievers this should be set to stop recieving, and for writers to close any files + stop writing.
- async send(data: bytes, *, flags: int = 0) None[source]¶
This function is a coroutine.
Sends data through stream, writers must include this method and should make sure each packet has an RTC header. To simplify this mess you should call
VoiceConnection._get_audio_packet.Note
When implementing writers, big files should be handled by you and for sending “complete” payloads, call
VoiceConnection.send_audio_packet.
BaserReceiver¶
- class acord.BasePlayer(conn: acord.voice.core.VoiceConnection, data: Union[io.BufferedIOBase, os.PathLike], encoder: Optional[acord.voice.opus.Encoder] = None, **encoder_kwargs)[source]¶
- async cleanup() None[source]¶
This function is a coroutine.
Cleans up any cache, if any. Should be implemented by recievers which save last recieved packet, and for writers should reset state of the writer
- close() None[source]¶
This function is a coroutine.
Closes this transport, leaving UDP connection open!
For recievers this should be set to stop recieving, and for writers to close any files + stop writing.
- async send(data: bytes, *, flags: int = 0) None[source]¶
This function is a coroutine.
Sends data through stream, writers must include this method and should make sure each packet has an RTC header. To simplify this mess you should call
VoiceConnection._get_audio_packet.Note
When implementing writers, big files should be handled by you and for sending “complete” payloads, call
VoiceConnection.send_audio_packet.
FfmpegPlayer¶
- asynccleanup
- class acord.FfmpegPlayer(conn: acord.voice.core.VoiceConnection, source_file: Union[io.BufferedIOBase, os.PathLike], encoder: Optional[acord.voice.opus.Encoder] = None, executable: str = 'ffmpeg', subprocess_args: tuple = (), subprocess_kwds: dict = {}, **encoder_kwds)[source]¶