(python) replit api reference.¶
Module contents¶
-
replit.
clear
()¶ Clear is used to clear the terminal.
-
exception
replit.
InvalidFileType
¶ Bases:
Exception
Exception for when a requested file’s type isnt valid
-
exception
replit.
NoSuchSourceException
¶ Bases:
Exception
Exception used when a source doesn’t exist
-
class
replit.
Source
(payload, loops)¶ Bases:
object
A Source is used to get audio that is sent to the user.
- Parameters
payload (
SourceData
) – The payload for the source.loops (int) – How many times the source should loop.
-
property
name
¶ The name of the source
- Return type
str
-
get_start_time
()¶ When the source started plaing
- Return type
datetime
-
property
start_time
¶ Property wrapper for
get_start_time()
- Return type
datetime
-
property
path
¶ The path to the source, if available.
- Return type
str
-
property
id
¶ The ID of the source.
- Return type
int
-
get_remaining
()¶ The estimated time remaining in the source’s current loop.
- Return type
timedelta
-
property
remaining
¶ Property wrapper for
get_remaining()
- Return type
timedelta
-
get_end_time
()¶ The estimated time when the sourcce will be done playing. Returns None if the source has finished playing. Note: this is the estimation for the end of the current loop.
- Return type
datetime
-
property
end_time
¶ Property wrapper for
get_end_time()
- Return type
datetime
-
property
does_loop
¶ Wether the source repeats itself or not.
- Return type
bool
-
property
duration
¶ The duration of the source.
- Return type
timedelta
-
get_volume
()¶ The volume the source is set to.
- Return type
float
-
set_volume
(volume)¶ - Parameters
volume (float) – The volume the source should be set to.
- Raises
NoSuchSourceException – If the source is no longer known to the audio manager.
-
property
volume
¶ Property wrapper for
get_volume()
andset_volume()
- Return type
float
-
get_paused
()¶ Wether the source is paused or not.
- Return type
bool
-
set_paused
(paused)¶ - Parameters
paused (bool) – Wether the source should be paused or not.
- Raises
NoSuchSourceException – If the source is no longer known to the audio manager.
-
property
paused
¶ Property wrapper for
get_paused()
andset_paused()
- Return type
bool
-
get_loops_remaining
()¶ The remaining amount of times the file will restart. Returns none if the source is done playing.
- Return type
int
- Returns
int – The number of loops remaining
None – The source can’t be found, either because it has finished playing or an error occured.
-
set_loop
(loop_count)¶ Set the remaining amount of loops for the source. Set loop_count to a negative value to repeat forever.
- Parameters
does_loop (bool) – Wether the source should be paused or not.
loop_count (int) – How many times the source should repeat itself. Set to a negative value for infinite.
- Raises
NoSuchSourceException – If the source is no longer known to the audio manager.
- Return type
None
-
property
loops_remaining
¶ Property wrapper for
get_loops_remaining()
- Return type
int
-
toggle_playing
()¶ Play/pause the source.
- Return type
None
-
class
replit.
Audio
¶ Bases:
object
The basic audio manager.
Notes
This is not intended to be called directly, instead use
audio
.Using this in addition to audio can cause major issues.
-
play_file
(file_path, volume=1, does_loop=False, loop_count=0, name='Source 1593028104.2264273')¶ Sends a request to play a file, assuming the file is valid.
- Parameters
file_path (str) – The path to the file that should be played. Can be absolute or relative.
volume (float, optional) – The volume the source should be played at. (1 being 100%)
does_loop (bool, optional) – Wether the source should repeat itself or not. Note, if you set this you should also set loop_count.
loop_count (int, optional) – How many times the source should repeat itself. Set to 0 to have the source play only once, or set to a negative value for the source to repeat forever.
name (str, optional) – The name of the file. Default value is a unique name for the source.
- Returns
The source created with the provided data.
- Return type
- Raises
FileNotFoundError – If the file is not found.
InvalidFileType – If the file type is not valid.
ValueError – If the type is not a valid type for a source.
-
play_tone
(duration, pitch, wave_type, does_loop=False, loop_count=0, volume=1, name='Source 1593028104.2264404')¶ Play a tone from a frequency and wave type.
- Parameters
duration (float) – How long the tone should be played (in seconds).
pitch (int) – The frequency the tone should be played at.
wave_type (WaveType) – The wave shape used to generate the tone.
volume (float) – The volume the tone should be played at (1 being 100%).
name (str) – The name of the source.
- Returns
The source for the tone.
- Return type
- Raises
TimeoutError – If the source isn’t found after 2 seconds.
ValueError – If the wave type isn’t valid.
-
get_source
(source_id)¶ Get a source by it’s ID
- Parameters
source_id (int) – The ID for the source that should be found.
- Returns
The source with the ID provided.
- Return type
- Raises
NoSourceFoundException – If the source isnt found or there isn’t any sources known to the audio manager.
-
read_status
()¶ Get the raw data for what’s playing. This is an api call, and shouldn’t be needed for general usage.
- Returns
The contents of /tmp/audioStatus.json
- Return type
AudioStaus
-
get_playing
()¶ Get a list of playing sources.
- Returns
A list of sources that aren’t paused.
- Return type
List[Source]
-
-
replit.
audio
= <replit.Audio object>¶ The interface used for all things audio. Can be used to play and fetch audio sources.
replit.types module¶
-
class
replit.types.
ReaderType
(value)¶ Bases:
enum.Enum
An Enum for the types of sources.
-
wav_file
= 'wav'¶ The type for a .wav file.
- Type
-
aiff_file
= 'aiff'¶ The type for a .aiff file.
- Type
-
mp3_file
= 'mp3'¶ The type for a .mp3 file.
- Type
-
tone
= 'tone'¶ The type for a generated tone.
- Type
-
-
class
replit.types.
WaveType
(value)¶ Bases:
enum.Enum
The different wave shapes that can be used for tone generation.
-
replit.types.
file_types
: List[replit.types.ReaderType] = [ReaderType.aiff_file, ReaderType.wav_file, ReaderType.mp3_file]¶ The different file types for sources in a list.
-
class
replit.types.
RequestArgs
(**kwargs)¶ Bases:
dict
The additional arguments for a request that are type-specific.
-
Pitch
: float¶ The pitch/frequency of the tone. Only used if the request type is tone.
- Type
float
-
Seconds
: float¶ The duration for the tone to be played. Only used if the request type is tone.
- Type
float
-
WaveType
: WaveType or int¶ The wave type of the tone. Only used if the request type is tone.
- Type
-
Path
: str¶ The path to the file to be read. Only used if the request is for a file type.
- Type
str
-
-
class
replit.types.
RequestData
(**kwargs)¶ Bases:
dict
A request to pid1 for a source to be played.
-
ID
: int¶ The ID of the source. Only used for updating a pre-existing source.
- Type
int
-
Paused
: bool or None¶ Wether the source with the provided ID should be paused or not. Can only be used when updating a source.
- Type
bool or None
-
Volume
: float¶ The volume the source should be played at. (1 being 100%)
- Type
float
-
DoesLoop
: bool¶ Wether the source should loop / repeat or not. Defaults to false.
- Type
bool
-
LoopCount
: int¶ How many times the source should loop / repeat. Defaults to 0.
- Type
int
-
Name
: str¶ The name of the source.
- Type
str
-
Type
: ReaderType or str¶ The type of the source.
- Type
-
Args
: RequestArgs¶ The additional arguments for the source.
- Type
-
-
class
replit.types.
SourceData
(**kwargs)¶ Bases:
dict
A source’s raw data, as a payload.
-
Name
: str¶ The name of the source.
- Type
str
-
Type
: str¶ The type of the source.
- Type
str
-
Volume
: float¶ The volume of the source.
- Type
float
-
Duration
: int¶ The duration of the source in milliseconds.
- Type
int
-
Remaining
: int¶ How many more milliseconds the source will be playing.
- Type
int
-
Paused
: bool¶ Wether the source is paused or not.
- Type
bool
-
Loop
: int¶ How many times the source will loop. If 0, the source will not repeat itself.
- Type
int
-
ID
: int¶ The ID of the source.
- Type
int
-
EndTime
: str¶ The estimated timestamp for when the source will finish playing.
- Type
str
-
StartTime
: str¶ When the source started playing.
- Type
str
-
Request
: RequestData¶ The request used to create the source.
- Type
-
-
class
replit.types.
AudioStatus
(**kwargs)¶ Bases:
dict
The raw data read from /tmp/audioStatus.json.
-
Sources
: List[SourceData] or None¶ The sources that are know to the audio manager.
- Type
List[SourceData]
-
Running
: bool¶ Wether the audio manager knows any sources or not.
- Type
bool
-
Disabled
: bool¶ Wether the audio manager is disabled or not.
- Type
bool
-