ibm-cloud-docs / text-to-speech

text-to-speech
6 stars 26 forks source link

Rehab #127

Closed RehabRozieak closed 4 years ago

RehabRozieak commented 4 years ago

import os from threading import Thread from watson_developer_cloud import VisualRecognitionV3 from ibm_watson import TextToSpeechV1 from ibm_cloud_sdk_core.authenticators import IAMAuthenticator import time import json import simpleaudio as sa from playsound import playsound import cv2

visual_recognition = VisualRecognitionV3(

,iam_apikey='')

visual_recognition = VisualRecognitionV3(

authenticator = IAMAuthenticator('Text to speech IAM auth')

text_to_speech = TextToSpeechV1( authenticator=authenticator ) text_to_speech.set_service_url('https://gateway-lon.watsonplatform.net/text-to-speech/api')

cascPath = ""

face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')

def getName(): ''' Get image and send it to Visual Recognition Returns name of class ''' time.sleep(1); classes = None; try: with open('temp.jpg', 'rb') as images_file: print("Success"); classes = visual_recognition.classify( images_file, threshold='0.6', classifier_ids='FaceDetectionGreeter_1201269096').getresult(); return classes['images'][0]['classifiers'][0]['classes'][0]['class']; except Exception: return "unrecognized person"; def transcribeName(name): name = name.replace('', ' '); name = "Hello, " + name; print(name); with open('person_name.wav', 'wb') as audio_file: audio_file.write( text_to_speech.synthesize( text=name, voice='en-US_AllisonVoice', accept='audio/wav'
).get_result().content) wave_obj = sa.WaveObject.from_wave_file("person_name.wav") play_obj = wave_obj.play() play_obj.wait_done() def detectFace(mirror=False): cam = cv2.VideoCapture(0) while True: ret_val, img = cam.read() if mirror: img = cv2.flip(img, 1) gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) cv2.imwrite('temp.jpg', img); transcribeName(getName()); def main(): detectFace();

getName();

if name == "main": main();