示例#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()
示例#2
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()
示例#3
0
def Voice():
    engineio = pyttsx3.init()
    voices = engineio.getProperty('voices')
    engineio.setProperty('rate', 130)
    engineio.setProperty('voice', voices[0].id)

    def speak(text):
        engineio.say(text)
        engineio.runAndWait()

    engineio = pyttsx3.init()
    voices = engineio.getProperty('voices')

    r = sr.Recognizer()
    #r.energy_threshold = 4000
    mic = sr.Microphone()

    while 1:

        with mic as source:
            print('Listening...')
            text = 'Listening...'
            speak(text)

            audio = r.listen(source)
            #r.adjust_for_ambient_noise(source, duration=0.5)
            #r.dynamic_energy_threshold = True        # listen to the source
            try:
                # use recognizer to convert our audio into text part.
                text = r.recognize_google(audio)
                print("You said : {}".format(text))
            except:
                # In case of voice not recognized  clearly
                print("Sorry could not recognize your voice")
                speak("Could not understand")

        if text == 'exit':
            equation.set('Good Bye :D')
            root.update_idletasks()
            speak("Good Bye")
            break
            #sys.exit("Thankyou !")
        elif text == "clear":
            equation.set(" ")

        a = ''
        b = ''
        i = 0
        j = 0
        c = len(text)
        while text[j] != ' ':
            a = a + text[j]
            j = j + 1
        j = j + 1
        ch = text[j]
        if ch == 'd':
            while text[j] != 'y':
                j = j + 1
            #j=j+1
        j = j + 2
        while j != c:
            b = b + text[j]
            j = j + 1

        a = float(a)
        b = float(b)

        ans = 0
        if ch == '+':
            ans = a + b
            equation.set(ans)
            root.update_idletasks()

        elif ch == '-':
            ans = a - b
            equation.set(ans)
            root.update_idletasks()

        elif ch == 'x' or ch == 'X':
            ans = a * b
            equation.set(round(ans, 2))
            root.update_idletasks()

        elif ch == '/' or ch == 'd':
            if b != 0:
                ans = a / b
                equation.set(round(ans, 2))
                root.update_idletasks()
            else:
                speak("Not defined")
                ans = 0
                #equation.set(round(ans,2))
                root.update_idletasks()
        elif ch == '^':
            ans = math.pow(a, b)
            equation.set(ans)
            root.update_idletasks()
        else:
            ans = "Invalid Command"

        print(round(ans, 2))
        equation.set(ans)
        speak("The answer is {}".format(round(ans, 2)))
示例#4
0
import speech_recognition as sr
from tkinter import *
from tkinter import messagebox
import random
import time
import datetime
import smtplib
import pyttsx3
import winsound
import engineio
import string
from random import randint
engineio = pyttsx3.init()
voices = engineio.getProperty('voices')
engineio.setProperty('rate', 130)
engineio.setProperty('voice', voices[0].id)
frequency = 4500
duration = 150


def speak(text):
    engineio.say(text)
    engineio.runAndWait()


#speak("hello world")

# creating root object
root = Tk()

# defining size of window
示例#5
0
def Voice():
    engineio = pyttsx3.init()
    voices = engineio.getProperty('voices')
    engineio.setProperty('rate', 130)
    engineio.setProperty('voice', 'ru')
    engineio.setProperty('voice', voices[0].id)

    def speak(text):
        engineio.say(text)
        engineio.runAndWait()

    engineio = pyttsx3.init()
    voices = engineio.getProperty('voices')

    r = sr.Recognizer()
    r.energy_threshold = 4000
    mic = sr.Microphone()

    while 1:

        with mic as source:
            print('Слушаю...')
            text = 'Слушаю...'
            speak(text)

            audio = r.listen(source)
            r.adjust_for_ambient_noise(source, duration=0.5)
            r.dynamic_energy_threshold = True  # listen to the source
            try:
                # use recognizer to convert our audio into text part.
                text = r.recognize_google(audio, language="ru_RU")
                print("Вы сказали : {}".format(text))
            except:
                # In case of voice not recognized  clearly
                print("Извините,не могу опознать голос")
                speak("Не могу опознать вашу команду")

        if text == 'выход' or text == 'выйти' or text == 'закрыть' or text == 'остановить' or text == 'выйти':
            equation.set('Начинаю подсчёт... ')
            root.update_idletasks()
            speak("Вы в режиме обычного калькулятора!")
        #elif text =='закрыть' or text=='Закрой'or text=='закончить': doesn't work correctly
        # sys.exit("До Свидания , Хорошего дня !")
        elif text == "Очисти" or text == 'сотри' or text == 'стереть':
            equation.set(" ")

        a = ''
        b = ''
        i = 0
        j = 0
        c = len(text)
        while text[j] != ' ':
            a = a + text[j]
            j = j + 1
        j = j + 1
        ch = text[j]
        if ch == 'd':
            while text[j] != 'y':
                j = j + 1
            #j=j+1
        j = j + 2
        while j != c:
            b = b + text[j]
            j = j + 1

        a = float(a)
        b = float(b)

        ans = 0
        if ch == '+' or ch == 'плюс' or ch == 'добавить' or ch == 'прибавить':
            ans = a + b
            equation.set(ans)
            root.update_idletasks()

        elif ch == '-' or ch == 'минус' or ch == 'отнять' or ch == 'вычесть':
            ans = a - b
            equation.set(ans)
            root.update_idletasks()

        elif ch == 'x' or ch == 'умножить' or ch == 'на' or ch == 'ножить':
            ans = a * b
            equation.set(round(ans, 2))
            root.update_idletasks()

        elif ch == '/' or ch == 'поделить' or ch == 'разделить' or ch == 'делить':
            if b != 0:
                ans = a / b
                equation.set(round(ans, 2))
                root.update_idletasks()
            else:
                speak("Не определено")
                ans = 0
                #equation.set(round(ans,2))
                root.update_idletasks()
        elif ch == '^' or ch == 'в' or ch == 'во' or ch == 'степень' or ch == 'степени' or ch == 'епень':
            ans = math.pow(a, b)
            equation.set(ans)
            root.update_idletasks()
        else:
            ans = "Некорректная команда"

        print(round(ans, 2))
        equation.set(ans)
        speak("Ответ: {}".format(round(ans, 2)))
示例#6
0
import speech_recognition as sr
import pyttsx as pys
import engineio
import datetime
import wikipedia
import os
import webbrowser
import playsound
from gtts import gTTS

engineio = pys.init()
engineio.setProperty('rate', 150)
voices = engineio.getProperty('voices')
engineio.setProperty('voice', voices[1].id)
volume = engineio.getProperty('volume')
engineio.setProperty('volume', 1.0)


def speak(audio):
    engineio.say(audio)
    engineio.runAndWait()


def saveVoice(audio):
    tts = gTTS(text=audio)
    filename = "voice.mp3"
    tts.save(filename)
    playsound.playsound(filename)


def Command():