Created
August 28, 2018 08:30
-
-
Save fthiery/09be29017434dfb2f372e3b7fd96af09 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python3 | |
| # -*- coding: utf-8 -*- | |
| # Copyright 2018, Florent Thiery | |
| import gi | |
| import sys | |
| gi.require_version('Gst', '1.0') | |
| from gi.repository import Gst, GLib | |
| Gst.init(None) | |
| try: | |
| input_file = sys.argv[1] | |
| except Exception: | |
| print('Need wave input file as argument') | |
| sys.exit() | |
| p = "filesrc location=%s ! wavparse ! level ! fakesink" % input_file | |
| print(p) | |
| def _on_message(bus, message): | |
| if message.type == Gst.MessageType.ELEMENT: | |
| struct = message.get_structure() | |
| sname = struct.get_name() | |
| if sname == 'level': | |
| ts = struct.get_value("timestamp") | |
| # you need gst-python gio overrides for arrays | |
| rms_array = struct.get_value("rms") | |
| print(ts, rms_array) | |
| pipeline = Gst.parse_launch(p) | |
| bus = pipeline.get_bus() | |
| bus.add_signal_watch() | |
| bus.connect("message", _on_message) | |
| GLib.idle_add(pipeline.set_state, Gst.State.PLAYING) | |
| ml = GLib.MainLoop() | |
| ml.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment