import speech_recognition as sr

r = sr.Recognizer()
m = sr.Microphone()

print("A moment of silence, please...")
with m as source:
    r.adjust_for_ambient_noise(source)
    print("Set minimum energy threshold to {}".format(r.energy_threshold))
    while True:
        print("Say something!")
        audio = r.listen(source)
        print("Got it! Now to recognize it...")
        try:
            value = r.recognize(audio)
            if str is bytes: # this version of Python uses bytes for strings (Python 2)
                print(u"You said {}".format(value).encode("utf-8"))
            else: # this version of Python uses unicode for strings (Python 3+)
                print("You said {}".format(value))
        except LookupError:
            print("Oops! Didn't catch that")

@@ -67,16 +67,25 @@
 hone()%0A%0A
+try:%0A    
 print(%22A
@@ -116,16 +116,20 @@
 se...%22)%0A
+    
 with m a
@@ -138,16 +138,20 @@
 source:%0A
+    
     r.ad
@@ -177,24 +177,28 @@
 ise(source)%0A
+    
     print(%22S
@@ -260,16 +260,20 @@
 shold))%0A
+    
     whil
@@ -280,32 +280,36 @@
 e True:%0A        
+ 
+   
 print(%22Say somet
@@ -316,16 +316,20 @@
 hing!%22)%0A
+    
         
@@ -357,24 +357,28 @@
 ce)%0A        
+    
 print(%22Got i
@@ -413,21 +413,29 @@
         
+  
+  
 try:%0A
+    
         
@@ -465,16 +465,20 @@
 (audio)%0A
+    
         
@@ -569,24 +569,28 @@
             
+   
+ 
 print(u%22You 
@@ -629,16 +629,20 @@
 tf-8%22))%0A
+    
         
@@ -725,24 +725,28 @@
             
+  
+  
 print(%22You s
@@ -768,16 +768,20 @@
 value))%0A
+    
         
@@ -808,24 +808,28 @@
             
+    
 print(%22Oops!
@@ -849,8 +849,43 @@
  that%22)%0A
+except KeyboardInterrupt:%0A    pass%0A

Handle Ctrl + C when running demo in the terminal.