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 threading
|
||||
import speech_recognition
|
||||
import pyttsx3
|
||||
from paho.mqtt import client as mqtt_client
|
||||
|
||||
broker = 'broker.emqx.io'
|
||||
@@ -29,12 +31,24 @@ def on_message(client, userdata, msg):
|
||||
global chat
|
||||
if str(msg.topic) != pubtop:
|
||||
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):
|
||||
global msg
|
||||
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':
|
||||
client.disconnect()
|
||||
print("Disconnected....")
|
||||
|
||||
Reference in New Issue
Block a user