TensorFlow-Lite-Object-Detection-on-Android-and-Raspberry-Pi icon indicating copy to clipboard operation
TensorFlow-Lite-Object-Detection-on-Android-and-Raspberry-Pi copied to clipboard

FPS drop while using tts to speak out the objects.

Open akashshingha850 opened this issue 4 years ago • 1 comments
trafficstars

Hello. I tried to add some lines in the script to use tts (epeak) to call out the object names. but when an object is detected, it slows down drastically ( it is very obvious because it needs to finish the process of tts before continuing the loop)

So I tried to write the detected object names in a separate file(txt) and use another script to extract the text and apply tts on that.. But this process is not that efficient.

Do you have idea or suggestion to resolve this issue?

akashshingha850 avatar Nov 24 '20 10:11 akashshingha850

You could consider using threading or asyncio to create a seperate Thread whenever an object is on screen. Something like:

import espeak
from threading import Thread # The script already imports Threads, for demonstration

es = espeak.ESpeak()

def speak_text(text):
    es.speak(text)

# The initial script...

# Line 199 onwards:
for i in range(len(scores)):
    if ((scores[i] > min_conf_threshold) and (scores[i] <= 1.0)):
         ymin = int(max(1,(boxes[i][0] * imH)))
         xmin = int(max(1,(boxes[i][1] * imW)))
         ymax = int(min(imH,(boxes[i][2] * imH)))
         xmax = int(min(imW,(boxes[i][3] * imW)))
            
         cv2.rectangle(frame, (xmin,ymin), (xmax,ymax), (10, 255, 0), 2)

         object_name = labels[int(classes[i])]
         # Start a new thread and pass the object's name as an argument
         Thread(target=speak_text, args=(object_name,), daemon=True).start()

But the overall performance always depends on the hardware this is running on.

stackxp avatar Jun 16 '24 19:06 stackxp