Ejemplo n.º 1
0
def speak(text):
    engineio = pyttsx3.init()
    voices = engineio.getProperty('voices')
    engineio.setProperty('rate',
                         130)  # Aquí puedes seleccionar la velocidad de la voz
    engineio.setProperty('voice', voices[0].id)
    engineio.say(text)
    engineio.runAndWait()
def identifyTrafficSign(image):
    '''
    In this function we select some ROI in which we expect to have the sign parts. If the ROI has more active pixels than threshold we mark it as 1, else 0
    After path through all four regions, we compare the tuple of ones and zeros with keys in dictionary SIGNS_LOOKUP
    '''

    # define the dictionary of signs segments so we can identify
    # each signs on the image
    SIGNS_LOOKUP = {
        (1, 0, 0, 1): 'Turn Right', # turnRight
        (0, 0, 1, 1): 'Turn Left', # turnLeft
        (0, 1, 0, 1): 'Move Straight', # moveStraight
        (1, 0, 1, 1): 'Turn Back', # turnBack
    }

    THRESHOLD = 150
    
    image = cv2.bitwise_not(image)
    # (roiH, roiW) = roi.shape
    #subHeight = thresh.shape[0]/10
    #subWidth = thresh.shape[1]/10
    (subHeight, subWidth) = np.divide(image.shape, 10)
    subHeight = int(subHeight)
    subWidth = int(subWidth)

    # mark the ROIs borders on the image
    cv2.rectangle(image, (subWidth, 4*subHeight), (3*subWidth, 9*subHeight), (0,255,0),2) # left block
    cv2.rectangle(image, (4*subWidth, 4*subHeight), (6*subWidth, 9*subHeight), (0,255,0),2) # center block
    cv2.rectangle(image, (7*subWidth, 4*subHeight), (9*subWidth, 9*subHeight), (0,255,0),2) # right block
    cv2.rectangle(image, (3*subWidth, 2*subHeight), (7*subWidth, 4*subHeight), (0,255,0),2) # top block

    # substract 4 ROI of the sign thresh image
    leftBlock = image[4*subHeight:9*subHeight, subWidth:3*subWidth]
    centerBlock = image[4*subHeight:9*subHeight, 4*subWidth:6*subWidth]
    rightBlock = image[4*subHeight:9*subHeight, 7*subWidth:9*subWidth]
    topBlock = image[2*subHeight:4*subHeight, 3*subWidth:7*subWidth]

    # we now track the fraction of each ROI
    leftFraction = np.sum(leftBlock)/(leftBlock.shape[0]*leftBlock.shape[1])
    centerFraction = np.sum(centerBlock)/(centerBlock.shape[0]*centerBlock.shape[1])
    rightFraction = np.sum(rightBlock)/(rightBlock.shape[0]*rightBlock.shape[1])
    topFraction = np.sum(topBlock)/(topBlock.shape[0]*topBlock.shape[1])

    segments = (leftFraction, centerFraction, rightFraction, topFraction)
    segments = tuple(1 if segment > THRESHOLD else 0 for segment in segments)

    cv2.imshow("Warped", image)
    if segments in SIGNS_LOOKUP:
        k=SIGNS_LOOKUP[segments]
        print(k)
        
        engineio.say(k)
        engineio.runAndWait()

        #print(p+" "+k)
        return SIGNS_LOOKUP[segments]        
    else:
        return None
Ejemplo n.º 3
0
def speak():
    "SPEAK 是存放输入字符串的列表,定义正全局变量"
    engineio = pyttsx3.init()  # 初始化
    voices = engineio.getProperty('voices')
    engineio.setProperty('rate', 130)  # 这里是管控语音速度的
    engineio.setProperty('voice', voices[0].id)

    if len(SPEAK):
        engineio.say(SPEAK[len(SPEAK) - 1])  # 获取最新输入的值
        engineio.runAndWait()
        data = SPEAK[0]
        if data != SPEAK[len(SPEAK) - 1]:  # 比较两个值要是不同就证明有新的值进入了,将原先的给删除掉
            del SPEAK[0]
    else:
        engineio.say("请输入你要翻译的英文或者汉字")
        engineio.runAndWait()
        sys.exit()
Ejemplo n.º 4
0
        return 'ask confirmation', preferences

    #default new state if we did not recognise the input / old state combination
    return 'ask to repeat', preferences

print('Done!\n')

while True:
    #give some output to the user
    output = generateOutput(currentstate)

    #text to speech output is available
    if textToSpeech == True:
        engineio = pyttsx3.init()
        engineio.say(output)
        engineio.runAndWait()

    #prints info for debugging purposes
    if verbose:
        print(currentstate)
        print(preferences)

    print(output)

    #presents user with info about remaining number of utterances
    if maxUtterances:
        if utterancecount != utterancemax:
            print('[', utterancemax - utterancecount, 'sentences left ]')

    #end program if we're done
    if currentstate == 'end' or currentstate == 'ran out of time':
Ejemplo n.º 5
0
 def speak(text):
     engineio.say(text)
     engineio.runAndWait()
Ejemplo n.º 6
0
def speak(text):
    engineio.say(text) # fala a string setada
    engineio.runAndWait() # executa e espera
Ejemplo n.º 7
0
def GLaDOS(audio):
    """speaks audio passed as argument"""
    print(audio)
    for line in audio.splitlines():
        engineio.say(audio)
        engineio.runAndWait()
Ejemplo n.º 8
0
def speak(text):  #Function to speak text
    engineio.say(text)
    engineio.runAndWait()
Ejemplo n.º 9
0
def speak(audio):
    engineio.say(audio)
    engineio.runAndWait()