Skip to content

Instantly share code, notes, and snippets.

@cenkersisman
Created July 3, 2019 12:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cenkersisman/8bd60a3a212f0d5bde6662d264a1a058 to your computer and use it in GitHub Desktop.
Save cenkersisman/8bd60a3a212f0d5bde6662d264a1a058 to your computer and use it in GitHub Desktop.
import speech_recognition as sr
from google_speech import Speech
import os
import time
import requests
import json
def getSound():
r = sr.Recognizer()
with sr.Microphone() as source:
print("Bir sey soyle!")
audio =r.adjust_for_ambient_noise(source)
audio = r.listen(source)
data = ""
try:
data = r.recognize_google(audio, language='tr-tr')
data = data.lower()
print(data)
except sr.UnknownValueError:
print("Konuşma anlaşılmadı!")
return data
data = getSound()
time.sleep(2)
params = dict(
username='volkan',
token='abc123',
code=data,
type='text'
)
print(data)
lang = "tr"
cevap = json.loads(requests.post("http://beta.ceyd-a.com/jsonengine.jsp", data=params).content.decode('utf-8')[1:-3]).get("answer")
print(cevap)
speech = Speech(cevap, lang)
speech.play()
time.sleep(2)
if("LEDOn" in cevap):
requests.post("http://192.168.4.2/LEDOn")
speech = Speech("lambayı yaktım", lang)
time.sleep(2)
speech.play()
time.sleep(2)
elif("LEDOff" in cevap):
requests.post("http://192.168.4.2/LEDOff")
speech = Speech("lambayı söndürdüm", lang)
time.sleep(2)
speech.play()
time.sleep(2)
elif(data=="lambayı yak"):
requests.post("http://192.168.4.2/LEDOn")
speech = Speech("lambayı yaktım", lang)
time.sleep(2)
speech.play()
time.sleep(2)
elif(data=="lambayı söndür"):
requests.post("http://192.168.4.2/LEDOff")
speech = Speech("lambayı söndürdüm", lang)
time.sleep(2)
speech.play()
time.sleep(2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment