Skip to content

Commit

Permalink
Check for the existence of speech_recognition package
Browse files Browse the repository at this point in the history
  • Loading branch information
jacebrowning committed Mar 16, 2016
1 parent 1eb1246 commit 9ad4398
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions scripts/run_gui.py
Expand Up @@ -5,7 +5,10 @@
import tkinter as tk
from tkinter import ttk
from PIL import Image, ImageTk
import speech_recognition
try:
import speech_recognition # pylint: disable=import-error
except ImportError:
speech_recognition = None

from memegen import __project__, __version__
from memegen.settings import ProdConfig
Expand All @@ -24,13 +27,16 @@ def __init__(self, app):
self._image = None
self._update_event = None
self._clear_event = None
self._recogizer = speech_recognition.Recognizer()
self._microphone = speech_recognition.Microphone()
with self._microphone as source:
log.info("Adjusting for ambient noise...")
self._recogizer.adjust_for_ambient_noise(source)
log.info("Listening in the background...")
self._recogizer.listen_in_background(self._microphone, self.listen)

# Configure speech recognition
if speech_recognition:
self._recogizer = speech_recognition.Recognizer()
self._microphone = speech_recognition.Microphone()
with self._microphone as source:
log.info("Adjusting for ambient noise...")
self._recogizer.adjust_for_ambient_noise(source)
log.info("Listening in the background...")
self._recogizer.listen_in_background(self._microphone, self.listen)

# Configure root window
self.root = tk.Tk()
Expand Down

0 comments on commit 9ad4398

Please sign in to comment.