Parlatype.Player

g GObject.Object GObject.Object Parlatype.Player Parlatype.Player GObject.Object->Parlatype.Player

Subclasses:

None

Methods

Inherited:

GObject.Object (37)

Structs:

GObject.ObjectClass (5)

class

get_time_string (time, duration, precision)

class

new ()

clear_selection ()

config_is_loadable (config)

configure_asr (config)

connect_waveviewer (wv)

get_back ()

get_current_time_string (precision)

get_duration ()

get_duration_time_string (precision)

get_filename ()

get_forward ()

get_mode ()

get_mute ()

get_pause ()

get_position ()

get_speed ()

get_timestamp ()

get_timestamp_for_time (time, duration)

get_timestamp_position (timestamp, check_duration)

get_uri ()

get_volume ()

goto_timestamp (timestamp)

has_selection ()

jump_back ()

jump_forward ()

jump_relative (milliseconds)

jump_to_position (milliseconds)

open_uri (uri)

pause ()

pause_and_rewind ()

play ()

play_pause ()

set_mode (type)

set_mute (mute)

set_selection (start, end)

set_speed (speed)

set_volume (volume)

string_is_timestamp (timestamp, check_duration)

Virtual Methods

Inherited:

GObject.Object (7)

Properties

Name

Type

Flags

Short Description

back

int

r/w

current-uri

str

r

forward

int

r/w

mute

bool

r/w/c

pause

int

r/w

repeat-all

bool

r/w

repeat-selection

bool

r/w

speed

float

r/w/c

state

int

r

timestamp-delimiter

str

r/w/c

timestamp-fixed

bool

r/w/c

timestamp-fraction-sep

str

r/w/c

timestamp-precision

int

r/w/c

volume

float

r/w/c

Signals

Inherited:

GObject.Object (1)

Name

Short Description

asr-final

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.

asr-hypothesis

The Parlatype.Player ::asr-hypothesis signal is emitted in automatic speech recognition mode as an intermediate result (hypothesis) of recognized words.

end-of-stream

The Parlatype.Player ::end-of-stream signal is emitted when the stream is at its end or when the end of selection is reached.

error

The Parlatype.Player ::error signal is emitted on errors opening the file or during playback.

jumped-back

The Parlatype.Player ::jumped-back signal is emitted when the player jumped back.

jumped-forward

The Parlatype.Player ::jumped-forward signal is emitted when the player jumped forward.

play-toggled

The Parlatype.Player ::play-toggled signal is emitted when the player changed to pause or play.

seek-done

The Parlatype.Player ::seek-done signal is emitted when a seek has finished successfully.

Fields

Inherited:

GObject.Object (1)

Name

Type

Access

Description

parent_instance

GObject.Object

r

Class Details

class Parlatype.Player(**kwargs)
Bases:

GObject.Object

Abstract:

No

Structure:

Parlatype.PlayerClass

classmethod get_time_string(time, duration, precision)
Parameters:
Returns:

the time string

Return type:

str

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:

Parlatype.Player

Returns a new Parlatype.Player in Parlatype.ModeType.PLAYBACK. The next step would be to open a file with Parlatype.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) – a Parlatype.Config

Returns:

True on success, otherwise False

Return type:

bool

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 of Parlatype.Player itself or an installed external plugin.

New in version 3.0.

configure_asr(config)
Parameters:

config (Parlatype.Config) – a Parlatype.Config

Raises:

GLib.Error

Returns:

True on success, otherwise False

Return type:

bool

Configure ASR setup with a Parlatype.Config instance. This is necessary before switching into Parlatype.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) – a Parlatype.Waveviewer

Connect a Parlatype.Waveviewer. The Parlatype.Player will monitor selections made in the Parlatype.Waveviewer and act accordingly.

New in version 1.6.

get_back()
Returns:

time to jump back in milliseconds

Return type:

int

Returns the value of Parlatype.Player :back.

New in version 1.6.

get_current_time_string(precision)
Parameters:

precision (Parlatype.PrecisionType) – a Parlatype.PrecisionType

Returns:

the time string

Return type:

str

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:

int

Returns the duration of stream.

New in version 1.5.

get_duration_time_string(precision)
Parameters:

precision (Parlatype.PrecisionType) – a Parlatype.PrecisionType

Returns:

the time string

Return type:

str

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:

str

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:

int

Returns the value of Parlatype.Player :forward.

New in version 1.6.

get_mode()
Returns:

the current mode

Return type:

Parlatype.ModeType

Get current output mode.

New in version 3.0.

get_mute()
Returns:

True for muted state, False for normal state

Return type:

bool

Get mute state of the audio stream.

New in version 2.1.

get_pause()
Returns:

time to rewind on pause in milliseconds

Return type:

int

Returns the value of Parlatype.Player :pause.

New in version 1.6.

get_position()
Returns:

position in milliseconds or -1 on failure

Return type:

int

Returns the current position in stream.

New in version 1.5.

get_speed()
Returns:

playback speed

Return type:

float

Returns current playback speed.

New in version 3.1.

get_timestamp()
Returns:

the timestamp

Return type:

str

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 and Parlatype.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:
  • time (int) – the time in milliseconds

  • duration (int) – duration in milliseconds

Returns:

the timestamp

Return type:

str

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 and Parlatype.Player :timestamp-delimiter.

New in version 1.6.

get_timestamp_position(timestamp, check_duration)
Parameters:
  • timestamp (str) – the timestamp

  • check_duration (bool) – checking the timestamp’s validity also check duration

Returns:

the time in milliseconds represented by the timestamp or -1 for invalid timestamps

Return type:

int

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:

str

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:

float

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:

True on success, False if the timestamp is not valid

Return type:

bool

Goes to the position of the timestamp. Returns false, if it’s not a valid timestamp.

New in version 1.4.

has_selection()
Returns:

True if there is a selection

Return type:

bool

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:

True if successful, otherwise False

Return type:

bool

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 or False on error. Errors are emitted async via Parlatype.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 and Parlatype.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 in Parlatype.ModeType.PLAYBACK. Before switching to Parlatype.ModeType.ASR the programmer has to call Parlatype.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/or Parlatype.Player ::asr-final signal. Start recognition with Parlatype.Player.play().

New in version 3.0.

set_mute(mute)
Parameters:

mute (bool) – a bool

Mute the player (with True) or set it back to normal volume (with False). 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:
  • start (int) – selection start time in milliseconds

  • end (int) – selection end time in milliseconds

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:
  • timestamp (str) – the string to be checked

  • check_duration (bool) – whether timestamp’s time is less or equal stream’s duration

Returns:

True if the timestamp is valid, False if not

Return type:

bool

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_duration True 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:

RUN_FIRST

Parameters:
  • player (Parlatype.Player) – The object which received the signal

  • word (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 see Parlatype.Player ::asr-hypothesis.

Parlatype.Player.signals.asr_hypothesis(player, word)
Signal Name:

asr-hypothesis

Flags:

RUN_FIRST

Parameters:
  • player (Parlatype.Player) – The object which received the signal

  • word (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 following Parlatype.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:

RUN_FIRST

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:

RUN_FIRST

Parameters:

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:

RUN_FIRST

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:

RUN_FIRST

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:

RUN_FIRST

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:

RUN_FIRST

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
Name:

back

Type:

int

Default Value:

10000

Flags:

READABLE, WRITABLE

Milliseconds to jump back.

Parlatype.Player.props.current_uri
Name:

current-uri

Type:

str

Default Value:

None

Flags:

READABLE

URI of the currently loaded stream.

Parlatype.Player.props.forward
Name:

forward

Type:

int

Default Value:

10000

Flags:

READABLE, WRITABLE

Milliseconds to jump forward.

Parlatype.Player.props.mute
Name:

mute

Type:

bool

Default Value:

False

Flags:

READABLE, WRITABLE, CONSTRUCT

Mute state of the audio stream.

Parlatype.Player.props.pause
Name:

pause

Type:

int

Default Value:

0

Flags:

READABLE, WRITABLE

Milliseconds to rewind on pause.

Parlatype.Player.props.repeat_all
Name:

repeat-all

Type:

bool

Default Value:

False

Flags:

READABLE, WRITABLE

“Play” at the end of the file replays it.

Parlatype.Player.props.repeat_selection
Name:

repeat-selection

Type:

bool

Default Value:

False

Flags:

READABLE, WRITABLE

“Play” at the end of a selection replays it.

Parlatype.Player.props.speed
Name:

speed

Type:

float

Default Value:

1.0

Flags:

READABLE, WRITABLE, CONSTRUCT

The speed for playback.

Parlatype.Player.props.state
Name:

state

Type:

int

Default Value:

0

Flags:

READABLE

The current state of Parlatype.Player.

Parlatype.Player.props.timestamp_delimiter
Name:

timestamp-delimiter

Type:

str

Default Value:

'#'

Flags:

READABLE, WRITABLE, CONSTRUCT

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
Name:

timestamp-fixed

Type:

bool

Default Value:

False

Flags:

READABLE, WRITABLE, CONSTRUCT

Whether timestamp format should have a fixed number of digits.

Parlatype.Player.props.timestamp_fraction_sep
Name:

timestamp-fraction-sep

Type:

str

Default Value:

'.'

Flags:

READABLE, WRITABLE, CONSTRUCT

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
Name:

timestamp-precision

Type:

int

Default Value:

1

Flags:

READABLE, WRITABLE, CONSTRUCT

How precise timestamps should be.

Parlatype.Player.props.volume
Name:

volume

Type:

float

Default Value:

1.0

Flags:

READABLE, WRITABLE, CONSTRUCT

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.