Parlatype.Player¶
- Subclasses:
None
Methods¶
- Inherited:
- Structs:
class |
|
class |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Virtual Methods¶
- Inherited:
Properties¶
Name |
Type |
Flags |
Short Description |
---|---|---|---|
r/w |
|||
r |
|||
r/w |
|||
r/w/c |
|||
r/w |
|||
r/w |
|||
r/w |
|||
r/w/c |
|||
r |
|||
r/w/c |
|||
r/w/c |
|||
r/w/c |
|||
r/w/c |
|||
r/w/c |
Signals¶
- Inherited:
Name |
Short Description |
---|---|
The |
|
The |
|
The |
|
The |
|
The |
|
The |
|
The |
|
The |
Fields¶
- Inherited:
Name |
Type |
Access |
Description |
---|---|---|---|
parent_instance |
r |
Class Details¶
- class Parlatype.Player(**kwargs)¶
- Bases:
- Abstract:
No
- Structure:
- classmethod get_time_string(time, duration, precision)¶
- Parameters:
time (
int
) – time in milliseconds to converseduration (
int
) – duration of stream in milliseconds (max time)precision (
Parlatype.PrecisionType
) – aParlatype.PrecisionType
- Returns:
the time string
- Return type:
Returns the given time as a string for display to the user. Format type is determined by duration, e.g. if duration is long format, it returns a string in long format, too.
New in version 1.4.
- classmethod new()¶
- Returns:
a new pt_player
- Return type:
Returns a new
Parlatype.Player
inParlatype.ModeType.PLAYBACK
. The next step would be to open a file withParlatype.Player.open_uri
().After use
GObject.Object.unref
() it.New in version 1.6.
- clear_selection()¶
Clear and reset any selection.
New in version 1.5.
- config_is_loadable(config)¶
- Parameters:
config (
Parlatype.Config
) – aParlatype.Config
- Returns:
- Return type:
Checks if
Parlatype.Player
is able to load the GStreamer plugin used by config without actually loading it. It does not guarantee that the plugin is functional, merely that it is either a private plugin ofParlatype.Player
itself or an installed external plugin.New in version 3.0.
- configure_asr(config)¶
- Parameters:
config (
Parlatype.Config
) – aParlatype.Config
- Raises:
- Returns:
- Return type:
Configure ASR setup with a
Parlatype.Config
instance. This is necessary before switching intoParlatype.ModeType.ASR
the first time. The configuration remains if you switch to normal playback and back to ASR again. Subsequently it can be changed in both modes.New in version 3.0.
- connect_waveviewer(wv)¶
- Parameters:
wv (
Parlatype.Waveviewer
) – aParlatype.Waveviewer
Connect a
Parlatype.Waveviewer
. TheParlatype.Player
will monitor selections made in theParlatype.Waveviewer
and act accordingly.New in version 1.6.
- get_back()¶
- Returns:
time to jump back in milliseconds
- Return type:
Returns the value of
Parlatype.Player
:back
.New in version 1.6.
- get_current_time_string(precision)¶
- Parameters:
precision (
Parlatype.PrecisionType
) – aParlatype.PrecisionType
- Returns:
the time string
- Return type:
Returns the current position of the stream as a string for display to the user.
If the current position can not be determined,
None
is returned.New in version 1.4.
- get_duration()¶
- Returns:
duration in milliseconds
- Return type:
Returns the duration of stream.
New in version 1.5.
- get_duration_time_string(precision)¶
- Parameters:
precision (
Parlatype.PrecisionType
) – aParlatype.PrecisionType
- Returns:
the time string
- Return type:
Returns the duration of the stream as a string for display to the user.
If the duration can not be determined,
None
is returned.New in version 1.4.
- get_filename()¶
- Returns:
the file name
- Return type:
Returns the display name of the currently open file or
None
if it can’t be determined.New in version 1.4.
- get_forward()¶
- Returns:
time to jump forward in milliseconds
- Return type:
Returns the value of
Parlatype.Player
:forward
.New in version 1.6.
- get_mode()¶
- Returns:
the current mode
- Return type:
Get current output mode.
New in version 3.0.
- get_mute()¶
-
Get mute state of the audio stream.
New in version 2.1.
- get_pause()¶
- Returns:
time to rewind on pause in milliseconds
- Return type:
Returns the value of
Parlatype.Player
:pause
.New in version 1.6.
- get_position()¶
- Returns:
position in milliseconds or -1 on failure
- Return type:
Returns the current position in stream.
New in version 1.5.
- get_speed()¶
- Returns:
playback speed
- Return type:
Returns current playback speed.
New in version 3.1.
- get_timestamp()¶
- Returns:
the timestamp
- Return type:
Returns the current timestamp as a string. The format of the timestamp can be influenced with
Parlatype.Player
:timestamp-precision
,Parlatype.Player
:timestamp-fixed
,Parlatype.Player
:timestamp-fraction-sep
andParlatype.Player
:timestamp-delimiter
.If the current position can not be determined,
None
is returned.New in version 1.4.
- get_timestamp_for_time(time, duration)¶
- Parameters:
- Returns:
the timestamp
- Return type:
Returns the timestamp for the given time as a string. Duration is needed for some short time formats, the resulting timestamp format depends on whether duration is less than one hour or more than (including) an hour (3600000 milliseconds).
The format of the timestamp can be influenced with
Parlatype.Player
:timestamp-precision
,Parlatype.Player
:timestamp-fixed
,Parlatype.Player
:timestamp-fraction-sep
andParlatype.Player
:timestamp-delimiter
.New in version 1.6.
- get_timestamp_position(timestamp, check_duration)¶
- Parameters:
- Returns:
the time in milliseconds represented by the timestamp or -1 for invalid timestamps
- Return type:
Returns the time in milliseconds represented by the timestamp or -1 for invalid timestamps.
New in version 1.6.
- get_uri()¶
- Returns:
the uri
- Return type:
Returns the URI of the currently open file or
None
if it can’t be determined.New in version 1.4.
- get_volume()¶
- Returns:
the current volume
- Return type:
Gets the volume on a scale between 0 and 1.
New in version 2.1.
- goto_timestamp(timestamp)¶
- Parameters:
timestamp (
str
) – the timestamp to go to- Returns:
- Return type:
Goes to the position of the timestamp. Returns false, if it’s not a valid timestamp.
New in version 1.4.
- has_selection()¶
-
Returns whether there is currently a selection set or not.
New in version 4.0.
- jump_back()¶
Jumps back the value of
Parlatype.Player
:back
.New in version 1.6.
- jump_forward()¶
Jumps forward the value of
Parlatype.Player
:forward
.New in version 1.6.
- jump_relative(milliseconds)¶
- Parameters:
milliseconds (
int
) – time in milliseconds to jump
Skips milliseconds in stream. A positive value means jumping ahead. If the resulting position would be beyond the end of stream (or selection), it goes to the end of stream (or selection). A negative value means jumping back. If the resulting position would be negative (or before the selection), it jumps to position 0:00 (or to the start of the selection).
New in version 1.4.
- jump_to_position(milliseconds)¶
- Parameters:
milliseconds (
int
) – position in milliseconds
Jumps to a given position in stream. The position is given in milliseconds starting from position 0:00. A position beyond the duration of stream (or outside the selection) is ignored.
New in version 1.4.
- open_uri(uri)¶
- Parameters:
uri (
str
) – the URI of the file- Returns:
- Return type:
Opens a local audio file for playback. It doesn’t work with videos or streams. Only one file can be open at a time, playlists are not supported by the backend. Opening a new file will close the previous one.
When closing a file or on object destruction
Parlatype.Player
tries to write the last position into the file’s metadata. On opening a file it reads the metadata and jumps to the last known position if found.The player is set to the paused state and ready for playback. To start playback use pt_player_play().
This operation blocks until it is finished. It returns
True
on success orFalse
on error. Errors are emitted async viaParlatype.Player
::error
signal.New in version 2.0.
- pause()¶
Sets the player to the paused state, meaning it stops playback and doesn’t change position. To resume playback use pt_player_play().
New in version 1.4.
- pause_and_rewind()¶
Like pt_player_pause(), additionally rewinds the value of
Parlatype.Player
:pause
in milliseconds.New in version 1.6.
- play()¶
Starts playback in playback mode at the defined speed until it reaches the end of stream (or the end of the selection). If the current position is at the end, playback will start from the beginning of the stream or selection.
In ASR mode it starts decoding the stream silently at the fastest possible speed and emitting textual results via the
Parlatype.Player
::asr-hypothesis
andParlatype.Player
::asr-final
signals.New in version 1.4.
- play_pause()¶
Toggles between playback and pause, rewinds on pause.
New in version 1.6.
- set_mode(type)¶
- Parameters:
type (
Parlatype.ModeType
) – the desired output mode
Set output mode. Initially
Parlatype.Player
is inParlatype.ModeType.PLAYBACK
. Before switching toParlatype.ModeType.ASR
the programmer has to callParlatype.Player.configure_asr
() and check the result. Setting the mode is an asynchronous operation and when done in paused state, it will happen only during the change to playing state.Currently this works only well when done in paused state, in playing state there are severe synchronisation issues. To get the results in ASR mode, connect to the
Parlatype.Player
::asr-hypothesis
and/orParlatype.Player
::asr-final
signal. Start recognition withParlatype.Player.play
().New in version 3.0.
- set_mute(mute)¶
-
Mute the player (with
True
) or set it back to normal volume (withFalse
). This remembers the volume level, so you don’t have to keep track of the old value.New in version 2.1.
- set_selection(start, end)¶
- Parameters:
Set a selection. If the current position is outside the selection, it will be set to the selection’s start position, otherwise the current position is not changed. Playing will end at the stop position and it’s not possible to jump out of the selection until it is cleared with
Parlatype.Player.clear_selection
.New in version 1.5.
- set_speed(speed)¶
- Parameters:
speed (
float
) – speed
Sets the speed of playback in the paused state as well as during playback. Normal speed is 1.0, everything above that is faster, everything below slower. A speed of 0 is not allowed, use
Parlatype.Player.pause
() instead. Recommended speed is starting from 0.5 as quality is rather poor below that. Parlatype doesn’t change the pitch during slower or faster playback.New in version 1.4.
- set_volume(volume)¶
- Parameters:
volume (
float
) – volume
Sets the volume on a scale between 0 and 1. Instead of using this method you could set the “volume” property.
New in version 1.4.
- string_is_timestamp(timestamp, check_duration)¶
- Parameters:
- Returns:
- Return type:
Returns whether the given string is a valid timestamp. With check_duration
False
it checks only for the formal validity of the timestamp. With check_durationTrue
the timestamp must be within the duration to be valid.See also
Parlatype.Player.goto_timestamp
() if you want to go to the timestamp’s position immediately after.New in version 1.4.
Signal Details¶
- Parlatype.Player.signals.asr_final(player, word)¶
- Signal Name:
asr-final
- Flags:
- Parameters:
player (
Parlatype.Player
) – The object which received the signalword (
str
) – recognized word(s)
The
Parlatype.Player
::asr-final
signal is emitted in automatic speech recognition mode whenever a word or a sequence of words was recognized and won’t change anymore. For intermediate results seeParlatype.Player
::asr-hypothesis
.
- Parlatype.Player.signals.asr_hypothesis(player, word)¶
- Signal Name:
asr-hypothesis
- Flags:
- Parameters:
player (
Parlatype.Player
) – The object which received the signalword (
str
) – probably recognized word(s)
The
Parlatype.Player
::asr-hypothesis
signal is emitted in automatic speech recognition mode as an intermediate result (hypothesis) of recognized words. The hypothesis can still change. The programmer is responsible for replacing an emitted hypothesis by either the next following hypothesis or a followingParlatype.Player
::asr-final
signal.It’s not necessary to connect to this signal if you want the final result only. However, it can take a few seconds until a final result is emitted and without an intermediate hypothesis the end user might have the impression that there is nothing going on.
- Parlatype.Player.signals.end_of_stream(player)¶
- Signal Name:
end-of-stream
- Flags:
- Parameters:
player (
Parlatype.Player
) – The object which received the signal
The
Parlatype.Player
::end-of-stream
signal is emitted when the stream is at its end or when the end of selection is reached.
- Parlatype.Player.signals.error(player, error)¶
- Signal Name:
error
- Flags:
- Parameters:
player (
Parlatype.Player
) – The object which received the signalerror (
GLib.Error
) – aGLib.Error
The
Parlatype.Player
::error
signal is emitted on errors opening the file or during playback. It’s a severe error and the player is always reset.
- Parlatype.Player.signals.jumped_back(player)¶
- Signal Name:
jumped-back
- Flags:
- Parameters:
player (
Parlatype.Player
) – The object which received the signal
The
Parlatype.Player
::jumped-back
signal is emitted when the player jumped back.
- Parlatype.Player.signals.jumped_forward(player)¶
- Signal Name:
jumped-forward
- Flags:
- Parameters:
player (
Parlatype.Player
) – The object which received the signal
The
Parlatype.Player
::jumped-forward
signal is emitted when the player jumped forward.
- Parlatype.Player.signals.play_toggled(player)¶
- Signal Name:
play-toggled
- Flags:
- Parameters:
player (
Parlatype.Player
) – The object which received the signal
The
Parlatype.Player
::play-toggled
signal is emitted when the player changed to pause or play.
- Parlatype.Player.signals.seek_done(player)¶
- Signal Name:
seek-done
- Flags:
- Parameters:
player (
Parlatype.Player
) – The object which received the signal
The
Parlatype.Player
::seek-done
signal is emitted when a seek has finished successfully. If several seeks are queued up, only the last one emits a signal.
Property Details¶
- Parlatype.Player.props.back¶
-
Milliseconds to jump back.
- Parlatype.Player.props.current_uri¶
-
URI of the currently loaded stream.
- Parlatype.Player.props.forward¶
-
Milliseconds to jump forward.
- Parlatype.Player.props.mute¶
-
Mute state of the audio stream.
- Parlatype.Player.props.pause¶
-
Milliseconds to rewind on pause.
- Parlatype.Player.props.repeat_all¶
-
“Play” at the end of the file replays it.
- Parlatype.Player.props.repeat_selection¶
-
“Play” at the end of a selection replays it.
- Parlatype.Player.props.speed¶
-
The speed for playback.
- Parlatype.Player.props.state¶
-
The current state of
Parlatype.Player
.
- Parlatype.Player.props.timestamp_delimiter¶
-
Character to delimit start and end of timestamp. Allowed values are “None”, hashtag “#”, left bracket “(” and left square bracket “[“.
Parlatype.Player
will of course end with a right (square) bracket if those are chosen. Any other character is changed to a hashtag “#”.
- Parlatype.Player.props.timestamp_fixed¶
-
Whether timestamp format should have a fixed number of digits.
- Parlatype.Player.props.timestamp_fraction_sep¶
-
Character to separate fractions of a second from seconds. Only point “.” and minus “-” are allowed. Any other character is changed to a point “.”.
- Parlatype.Player.props.timestamp_precision¶
-
How precise timestamps should be.
- Parlatype.Player.props.volume¶
-
The volume for playback.
Pulseaudio sink does not propagate volume changes at GST_STATE_PAUSED or lower. This property will notify of changes only in GST_STATE_PLAYING and on state changes, e.g. from GST_STATE_READY to GST_STATE_PAUSED. Getting this property returns the real current volume level even if there was no notification before.