Last time, I wrote up to the part to record using socket communication. This time, I would like to make the part to notify by voice after socket communication.
When an object is detected on Yolov5 ➡ Socket communication is performed. ➡ Sound is played when socket communication is received.
Client side
detect.py
if label1=="chair":
print("Detected a chair.")
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s2:
s2.connect(('127.0.0.1', 50007))
s2.sendall(b'isukenti')
data = s2.recv(1024)
server.py
from playsound import playsound
import socket
# AF =Means IPv4
# TCP/For IP, SOCK_Use STREAM
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
#Specify IP address and port
s.bind(('127.0.0.1', 50007))
#1 connection
s.listen(1)
#Wait until you connect
while True:
#When someone visits, enter the connection and address
conn, addr = s.accept()
with conn:
while True:
#Receive data
data = conn.recv(1024)
if not data:
break
#print('data : {}, addr: {}'.format(data, addr))
conn.sendall(b'Received: ' + data)
playsound('2.wav')
#Return data to client(b ->Must be byte)
Basically, I'm just playing the audio using playsound ().
I'm using this for voice creation. https://w.atwiki.jp/softalk/
Next time, I'd like to write a story with a little more content, but since I want to post the implementation as it is, it may end up as an article without content. I'm sorry. Next time, I would like to write a program that separates sounds for each object. Thank you.
https://youtu.be/ua45mDZaiJM
Recommended Posts