speech_recognition
gstreamer_app.py
Go to the documentation of this file.
1 # Make python 2/3 compatible
2 from __future__ import (absolute_import, division,
3  print_function, unicode_literals)
4 from builtins import *
5 
6 import sys
7 import gi
8 gi.require_version('Gst', '1.0')
9 from gi.repository import Gst
10 
11 
12 class GstApp:
13  """Base class for Gstreamer Kaldi application"""
14  def __init__(self):
15  """Initialize the speech components"""
16  self.type = 'Gstreamer'
17  self.pulsesrc = Gst.ElementFactory.make("pulsesrc", "pulsesrc")
18  if self.pulsesrc is None:
19  self._error("Error loading pulsesrc GST plugin. You probably need the gstreamer1.0-pulseaudio package")
20 
21  self.audioconvert = Gst.ElementFactory.make("audioconvert", "audioconvert")
22  self.audioresample = Gst.ElementFactory.make("audioresample", "audioresample")
23  self.fakesink = Gst.ElementFactory.make("fakesink", "fakesink")
24 
25  # Generate Gstreamer pipeline (from source to sink)
26  self.pipeline = Gst.Pipeline()
27  for element in [self.pulsesrc, self.audioconvert, self.audioresample, self.fakesink]:
28  self.pipeline.add(element)
29  self.pulsesrc.link(self.audioconvert)
30  self.audioconvert.link(self.audioresample)
31 
32  def _error(self, *args, **kwargs):
33  """Print errors to stderr and exit program"""
34  print("[{}]".format(self.type), *args, file=sys.stderr, **kwargs)
35  sys.exit(1)
36 
speech_recognition.gstreamer_app.GstApp.audioresample
audioresample
Definition: gstreamer_app.py:22
speech_recognition.gstreamer_app.GstApp.type
type
Definition: gstreamer_app.py:16
speech_recognition.gstreamer_app.GstApp.__init__
def __init__(self)
Definition: gstreamer_app.py:14
speech_recognition.gstreamer_app.GstApp
Definition: gstreamer_app.py:12
speech_recognition.gstreamer_app.GstApp.pulsesrc
pulsesrc
Definition: gstreamer_app.py:17
speech_recognition.gstreamer_app.GstApp.fakesink
fakesink
Definition: gstreamer_app.py:23
speech_recognition.gstreamer_app.GstApp._error
def _error(self, *args, **kwargs)
Definition: gstreamer_app.py:32
speech_recognition.gstreamer_app.GstApp.audioconvert
audioconvert
Definition: gstreamer_app.py:21
speech_recognition.gstreamer_app.GstApp.pipeline
pipeline
Definition: gstreamer_app.py:26