import sys, time

import gi
gi.require_version('Gst', '1.0')
from gi.repository import Gst

Gst.init(sys.argv)

pipe = Gst.parse_launch('filesrc location="audio.wav" ! wavparse ! audioconvert ! scaletempo name=st ! autoaudiosink')
scaletempo = pipe.get_by_name('st')

pipe.set_state(Gst.State.PLAYING)
pipe.get_state(Gst.SECOND)

pipe.seek(
    2.0,
    Gst.Format.TIME,
    Gst.SeekFlags.NONE,
    Gst.SeekType.NONE, 0,
    Gst.SeekType.NONE, 0,
)
# give some time to execute the seek
time.sleep(1)

# query new_segment
query = Gst.Query.new_segment(Gst.Format.TIME)
pipe.query(query)
print(query.parse_segment())

# scaletempo "rate" is correct
print(scaletempo.get_property('rate'))

print('\nBye :-)')