Top | ![]() |
![]() |
![]() |
![]() |
gint | back | Read / Write |
gint | forward | Read / Write |
gint | pause | Read / Write |
gboolean | repeat-all | Read / Write |
gboolean | repeat-selection | Read / Write |
gdouble | speed | Read / Write / Construct |
gchar * | timestamp-delimiter | Read / Write / Construct |
gboolean | timestamp-fixed | Read / Write / Construct |
gchar * | timestamp-fraction-sep | Read / Write / Construct |
gint | timestamp-precision | Read / Write / Construct |
gdouble | volume | Read / Write / Construct |
void | asr-final | Run First |
void | asr-hypothesis | Run First |
void | end-of-stream | Run First |
void | error | Run First |
void | jumped-back | Run First |
void | jumped-forward | Run First |
void | load-progress | Run First |
void | play-toggled | Run First |
PtPlayer is the GStreamer backend for Parlatype. Construct it with pt_player_new()
.
Then you have to open a file, either with pt_player_open_uri_async()
or
pt_player_open_uri()
, the blocking version.
The internal time unit in PtPlayer are milliseconds and for scale widgets there is a scale from 0 to 1000. Use it to jump to a position or to update your widget.
While playing PtPlayer emits these signals:
end-of-stream: End of file reached, in the GUI you might want to jump to the beginning, reset play button etc.
error: A fatal error occured, the player is reset. There’s an error message.
PtPlayer has two properties:
speed: is a double from 0.5 to 1.5. 1.0 is normal playback, < 1.0 is slower, > 1.0 is faster. Changing the "speed" property doesn’t change playback though. Use the method instead.
Volume is a double from 0 to 1. It can be set via the method or setting the "volume" property.
PtPlayer *
pt_player_new (void
);
Returns a new PtPlayer. You have to set it up for playback with
pt_player_setup_player()
before doing anything else.
After use g_object_unref()
it.
gboolean pt_player_setup_player (PtPlayer *player
,GError **error
);
Setup the GStreamer pipeline for playback. This or pt_player_setup_sphinx()
must be called first on a new PtPlayer object. It’s a programmer’s error to
do anything with the PtPlayer before calling the setup function.
gboolean pt_player_setup_sphinx (PtPlayer *player
,GError **error
);
Setup the GStreamer pipeline for automatic speech recognition using
CMU sphinx. This loads resources like language model and dictionary and
might take a few seconds.
There is no audio output in this mode. Connect to the
“asr-hypothesis” and/or “asr-final” signal to get
the results. Start recognition with pt_player_play()
.
void pt_player_open_uri_async (PtPlayer *player
,gchar *uri
,GAsyncReadyCallback callback
,gpointer user_data
);
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 PtPlayer 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 is an asynchronous operation, to get the result call
pt_player_open_uri_finish()
in your callback. For the blocking version see
pt_player_open_uri()
.
While loading the file there is a “load-progress” signal emitted which stops before reaching 100%. Don’t use it to determine whether the operation is finished.
player |
a PtPlayer |
|
uri |
the URI of the file |
|
callback |
a GAsyncReadyCallback to call when the operation is complete. |
[scope async] |
user_data |
user_data for callback. |
[closure] |
gboolean pt_player_open_uri_finish (PtPlayer *player
,GAsyncResult *result
,GError **error
);
Gives the result of the async opening operation. A cancelled operation results in an error, too.
player |
a PtPlayer |
|
result |
the GAsyncResult passed to your GAsyncReadyCallback |
|
error |
a pointer to a NULL GError, or NULL. |
[nullable] |
gboolean pt_player_open_uri (PtPlayer *player
,gchar *uri
,GError **error
);
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 PtPlayer 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 and an error. For the asynchronous version see
pt_player_open_uri_async()
.
While loading the file there is a “load-progress” signal emitted. However, it doesn’t emit 100%, the operation is finished when TRUE is returned.
player |
a PtPlayer |
|
uri |
the URI of the file |
|
error |
return location for an error, or NULL. |
[nullable] |
void
pt_player_cancel (PtPlayer *player
);
Cancels the file opening operation, which triggers an error message.
void
pt_player_play (PtPlayer *player
);
Starts playback 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 stream or selection.
void
pt_player_play_pause (PtPlayer *player
);
Toggles between playback and pause, rewinds on pause.
void
pt_player_pause (PtPlayer *player
);
Sets the player to the paused state, meaning it stops playback and doesn’t
change position. To resume playback use
.pt_player_play()
void
pt_player_pause_and_rewind (PtPlayer *player
);
Like
, additionally rewinds the value of
“pause” in milliseconds.pt_player_pause()
void pt_player_connect_waveviewer (PtPlayer *player
,PtWaveviewer *wv
);
Connect a PtWaveviewer. The PtPlayer will monitor selections made in the PtWaveviewer and act accordingly.
void pt_player_set_selection (PtPlayer *player
,gint64 start
,gint64 end
);
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 pt_player_clear_selection.
player |
a PtPlayer |
|
start |
selection start time in milliseconds |
|
end |
selection end time in milliseconds |
void
pt_player_clear_selection (PtPlayer *player
);
Clear and reset any selection.
void pt_player_jump_relative (PtPlayer *player
,gint milliseconds
);
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).
void
pt_player_jump_forward (PtPlayer *player
);
Jumps forward the value of “forward”.
void pt_player_jump_to_position (PtPlayer *player
,gint 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.
void pt_player_jump_to_permille (PtPlayer *player
,guint permille
);
This is used for scale widgets. Start of stream is at 0, end of stream is at 1000. This will jump to the given position. If your widget uses a different scale, it’s up to you to convert it to 1/1000. Values beyond 1000 are not allowed, values outside the selection are ignored.
gint
pt_player_get_permille (PtPlayer *player
);
This is used for scale widgets. If the scale has to synchronize with the current position in stream, this gives the position on a scale between 0 and 1000.
Failure in querying the position returns -1.
void pt_player_set_speed (PtPlayer *player
,gdouble 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 pt_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.
Note: If you want to change the speed during playback, you have to use this method. Changing the "speed" property of PtPlayer, will take effect only later.
void pt_player_set_volume (PtPlayer *player
,gdouble volume
);
Sets the volume on a scale between 0 and 1. Instead of using this method you could set the "volume" property.
void pt_player_mute_volume (PtPlayer *player
,gboolean mute
);
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.
void pt_player_rewind (PtPlayer *player
,gdouble speed
);
Rewinds at the given speed. speed
accepts positive as well as negative
values and normalizes them to play backwards.
Note that depending on the file/stream format this works more or less good.
void pt_player_fast_forward (PtPlayer *player
,gdouble speed
);
Play fast forward at the given speed.
gint64
pt_player_get_position (PtPlayer *player
);
Returns the current position in stream.
gint64
pt_player_get_duration (PtPlayer *player
);
Returns the duration of stream.
gchar *
pt_player_get_uri (PtPlayer *player
);
Returns the URI of the currently open file or NULL if it can’t be determined.
gchar *
pt_player_get_filename (PtPlayer *player
);
Returns the display name of the currently open file or NULL if it can’t be determined.
gchar * pt_player_get_time_string (gint time
,gint duration
,PtPrecisionType precision
);
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.
gchar * pt_player_get_current_time_string (PtPlayer *player
,PtPrecisionType precision
);
Returns the current position of the stream as a string for display to the user.
If the current position can not be determined, NULL is returned.
gchar * pt_player_get_duration_time_string (PtPlayer *player
,PtPrecisionType precision
);
Returns the duration of the stream as a string for display to the user.
If the duration can not be determined, NULL is returned.
gchar * pt_player_get_timestamp_for_time (PtPlayer *player
,gint time
,gint duration
);
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 “timestamp-precision”, “timestamp-fixed”, “timestamp-fraction-sep” and “timestamp-delimiter”.
gchar *
pt_player_get_timestamp (PtPlayer *player
);
Returns the current timestamp as a string. The format of the timestamp can be influenced with “timestamp-precision”, “timestamp-fixed”, “timestamp-fraction-sep” and “timestamp-delimiter”.
If the current position can not be determined, NULL is returned.
gint pt_player_get_timestamp_position (PtPlayer *player
,gchar *timestamp
,gboolean check_duration
);
Returns the time in milliseconds represented by the timestamp or -1 for invalid timestamps.
player |
a PtPlayer |
|
timestamp |
the timestamp |
|
check_duration |
checking the timestamp’s validity also check duration |
gboolean pt_player_string_is_timestamp (PtPlayer *player
,gchar *timestamp
,gboolean check_duration
);
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 pt_player_goto_timestamp()
if you want to go to the timestamp’s
position immediately after.
player |
a PtPlayer |
|
timestamp |
the string to be checked |
|
check_duration |
whether timestamp’s time is less or equal stream’s duration |
gboolean pt_player_goto_timestamp (PtPlayer *player
,gchar *timestamp
);
Goes to the position of the timestamp. Returns false, if it’s not a valid timestamp.
PtWavedata * pt_player_get_data (PtPlayer *player
,gint pps
);
Returns wave data needed for visual representation as raw data. The requested resolution is given as pixel per seconds, e.g. 100 means one second is represented by 100 samples, is 100 pixels wide. The returned resolution doesn’t have to be necessarily exactly the requested resolution, it might be a bit differnt, depending on the bit rate.
struct PtPlayer;
The PtPlayer contains only private fields and should not be directly accessed.
“back”
property “back” gint
Milliseconds to jump back.
Flags: Read / Write
Allowed values: [1000,60000]
Default value: 10000
“forward”
property “forward” gint
Milliseconds to jump forward.
Flags: Read / Write
Allowed values: [1000,60000]
Default value: 10000
“pause”
property “pause” gint
Milliseconds to rewind on pause.
Flags: Read / Write
Allowed values: [0,10000]
Default value: 0
“repeat-all”
property “repeat-all” gboolean
"Play" at the end of the file replays it.
Flags: Read / Write
Default value: FALSE
“repeat-selection”
property “repeat-selection” gboolean
"Play" at the end of a selection replays it.
Flags: Read / Write
Default value: FALSE
“speed”
property “speed” gdouble
The speed for playback.
Flags: Read / Write / Construct
Allowed values: [0.1,2]
Default value: 1
“timestamp-delimiter”
property “timestamp-delimiter” gchar *
Character to delimit start and end of timestamp. Allowed values are "None", hashtag "#", left bracket "(" and left square bracket "[". PtPlayer will of course end with a right (square) bracket if those are chosen. Any other character is changed to a hashtag "#".
Flags: Read / Write / Construct
Default value: "#"
“timestamp-fixed”
property “timestamp-fixed” gboolean
Whether timestamp format should have a fixed number of digits.
Flags: Read / Write / Construct
Default value: FALSE
“timestamp-fraction-sep”
property “timestamp-fraction-sep” gchar *
Character to separate fractions of a second from seconds. Only point "." and minus "-" are allowed. Any other character is changed to a point ".".
Flags: Read / Write / Construct
Default value: "."
“timestamp-precision”
property “timestamp-precision” gint
How precise timestamps should be.
Flags: Read / Write / Construct
Allowed values: [0,3]
Default value: 1
“asr-final”
signalvoid user_function (PtPlayer *player, gchar *word, gpointer user_data)
The “asr-final” signal is emitted in automatic speech recognition mode whenever a word or a sequence of words was recognized.
player |
the player emitting the signal |
|
word |
recognized word(s) |
|
user_data |
user data set when the signal handler was connected. |
Flags: Run First
“asr-hypothesis”
signalvoid user_function (PtPlayer *player, gchar *word, gpointer user_data)
The “asr-hypothesis” signal is emitted in automatic speech recognition mode as an intermediate result (hypothesis) of recognized words. The hypothesis can still change, an emitted hypothesis replaces the former hypothesis and is finalized via the “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.
player |
the player emitting the signal |
|
word |
probably recognized word(s) |
|
user_data |
user data set when the signal handler was connected. |
Flags: Run First
“end-of-stream”
signalvoid user_function (PtPlayer *player, gpointer user_data)
The “end-of-stream” signal is emitted when the stream is at its end or when the end of selection is reached.
player |
the player emitting the signal |
|
user_data |
user data set when the signal handler was connected. |
Flags: Run First
“error”
signalvoid user_function (PtPlayer *player, GError *error, gpointer user_data)
The “error” signal is emitted on errors opening the file or during playback. It’s a severe error and the player is always reset.
player |
the player emitting the signal |
|
error |
a GError |
|
user_data |
user data set when the signal handler was connected. |
Flags: Run First
“jumped-back”
signalvoid user_function (PtPlayer *player, gpointer user_data)
The “jumped-back” signal is emitted when the player jumped back.
player |
the player emitting the signal |
|
user_data |
user data set when the signal handler was connected. |
Flags: Run First
“jumped-forward”
signalvoid user_function (PtPlayer *player, gpointer user_data)
The “jumped-forward” signal is emitted when the player jumped forward.
player |
the player emitting the signal |
|
user_data |
user data set when the signal handler was connected. |
Flags: Run First
“load-progress”
signalvoid user_function (PtPlayer *player, gdouble progress, gpointer user_data)
Indicates progress on a scale from 0.0 to 1.0, however it does not emit the value 0.0 nor 1.0. Wait for a TRUE player-state-changed signal or an error signal to dismiss a gui element showing progress.
player |
the player emitting the signal |
|
progress |
the new progress state, ranging from 0.0 to 1.0 |
|
user_data |
user data set when the signal handler was connected. |
Flags: Run First
“play-toggled”
signalvoid user_function (PtPlayer *player, gpointer user_data)
The “play-toggled” signal is emitted when the player changed to pause or play.
player |
the player emitting the signal |
|
user_data |
user data set when the signal handler was connected. |
Flags: Run First