Update mss.py
add 'speech to text' and 'text to speech'
This commit is contained in:
18
mss.py
18
mss.py
@@ -1,5 +1,7 @@
|
|||||||
import time
|
import time
|
||||||
import threading
|
import threading
|
||||||
|
import speech_recognition
|
||||||
|
import pyttsx3
|
||||||
from paho.mqtt import client as mqtt_client
|
from paho.mqtt import client as mqtt_client
|
||||||
|
|
||||||
broker = 'broker.emqx.io'
|
broker = 'broker.emqx.io'
|
||||||
@@ -29,12 +31,24 @@ def on_message(client, userdata, msg):
|
|||||||
global chat
|
global chat
|
||||||
if str(msg.topic) != pubtop:
|
if str(msg.topic) != pubtop:
|
||||||
chat = str(msg.payload.decode("utf-8"))
|
chat = str(msg.payload.decode("utf-8"))
|
||||||
print("\nCustom :", chat)
|
chat = str(msg.payload.decode("utf-8"))
|
||||||
|
robot_mouth = pyttsx3.init()
|
||||||
|
robot_mouth.say(chat)
|
||||||
|
robot_mouth.runAndWait()
|
||||||
|
|
||||||
def publish(client):
|
def publish(client):
|
||||||
global msg
|
global msg
|
||||||
while True:
|
while True:
|
||||||
msg = input("You :")
|
robot_ear = speech_recognition.Recognizer()
|
||||||
|
with speech_recognition.Microphone() as mic:
|
||||||
|
print("robot : im listen")
|
||||||
|
audio = robot_ear.listen(mic)
|
||||||
|
|
||||||
|
try:
|
||||||
|
msg = robot_ear.recognize_google(audio)
|
||||||
|
except:
|
||||||
|
msg = ""
|
||||||
|
|
||||||
if msg == 'stop' or msg == 'Stop':
|
if msg == 'stop' or msg == 'Stop':
|
||||||
client.disconnect()
|
client.disconnect()
|
||||||
print("Disconnected....")
|
print("Disconnected....")
|
||||||
|
|||||||
Reference in New Issue
Block a user