Unknown
Unknown

Reputation: 11

How can i add an sound alert if it detected the object

Hey im new to Python and my question is how can i add an alert sound if the system detected the object in the game :)

I gave the object im searching for the variable: vision_Logo

# initialize the WindowCapture class
wincap = WindowCapture('Main Phone')
# initialize the Vision class
vision_Logo = Vision('Logo.jpg')


# HSV filter
hsv_filter = HsvFilter(15, 45, 190, 29, 170, 255, 85, 100, 0, 10)


while(True):

    # get an updated image of the game
    screenshot = wincap.get_screenshot()

    # pre-process the image
    processed_image = vision_Logo.apply_hsv_filter(screenshot, hsv_filter)

    # do object detection
    rectangles = vision_Logo.find(processed_image, 0.41)

    # draw the detection results onto the original image
    output_image = vision_Logo.draw_rectangles(screenshot, rectangles)


    # display the processed image
    cv.imshow('Matches', output_image)

    # press 'q' with the output window focused to exit.
    # waits 1 ms every loop to process key presses
    if cv.waitKey(1) == ord('q'):
        cv.destroyAllWindows()
        break

print('Done.')

Upvotes: 1

Views: 1087

Answers (1)

Thaer A
Thaer A

Reputation: 2323

You can use the playsound module to play sounds in Python. After installing playsound using pip, import it and use the playsound function:

from playsound import playsound
.
.
.
.
playsound('soundfile.mp3')
print('Done.')

playsound Documentation: https://pypi.org/project/playsound/

Upvotes: 2

Related Questions