파이썬을 사용한 가상 어시스턴트

4161 단어 pythonbotai

인공지능을 위한 파이썬!!



Python 모듈은 함수, 클래스 및 변수를 정의하는 AI 기반 솔루션에서 매우 중요한 역할을 합니다. 모듈에는 실행 가능한 코드도 포함될 수 있습니다. 관련 코드를 모듈로 그룹화하면 코드를 더 쉽게 이해하고 사용할 수 있습니다. 또한 코드를 논리적으로 구성합니다.

중고 모듈;
1) 음성 인식
2) pyttsx3
3) 피아오디오
4) 위키피디아
5) 날짜/시간

음성 인식
컴퓨터가 인간의 언어를 이해할 수 있도록 합니다. 음성 인식은 말을 듣고 식별하는 기계의 능력입니다. 그런 다음 Python에서 음성 인식을 사용하여 음성 단어를 텍스트로 변환하거나 쿼리를 작성하거나 응답할 수 있습니다.

pyttsx3
pyttsx3는 Python의 텍스트 음성 변환 라이브러리입니다. 입력한 텍스트를 음성으로 변환하는 매우 사용하기 쉬운 도구입니다.

피아오디오
PyAudio는 플랫폼 간 오디오 I/O 라이브러리인 PortAudio에 대한 Python 바인딩을 제공합니다. PyAudio를 사용하면 Python을 사용하여 다양한 플랫폼에서 오디오를 쉽게 재생하고 녹음할 수 있습니다.

파이왓킷
youtube.Function pywhatkit.playonyt()에서 노래를 재생하는 데 사용되는 모듈은 기본 브라우저에서 YouTube를 열고 기능에서 언급한 비디오를 재생합니다. 주제 이름을 매개변수로 전달하면 해당 주제에 대한 임의의 비디오를 재생합니다. 비디오의 URL을 매개변수로 전달하면 정확한 비디오가 열립니다.

구문: pywhatkit.playonyt("검색 이름")

위키피디아
Wikipedia는 Wikipedia의 데이터에 쉽게 액세스하고 구문 분석할 수 있는 Python 라이브러리입니다. wikipedia의 모든 데이터는 여기에서 텍스트 또는 오디오 출력으로 사용할 수 있습니다.

날짜 시간
필요한 경우 많은 속성에서 타임스탬프로 사용할 수 있는 현재 날짜를 반환하는 데 사용됩니다.

import speech_recognition as sr
import pyttsx3
import pyaudio
import wikipedia
import pywhatkit
from datetime import datetime

now = datetime.now()
current_time = now.strftime("%H"  "%M")
cam = ["who", "when", "why", "what", "where"]


listener = sr.Recognizer()
on = pyttsx3.init()
newVoiceRate = 129
on.setProperty("rate", newVoiceRate)
voices = on.getProperty('voices')
on.setProperty('voice', voices[1].id)
on.say("hello vishak what can i do for you")
on.runAndWait()
def talk(lm):
    on.say(lm)
    on.runAndWait()
def take():
    try:
        with sr.Microphone() as source:
            print("listening...")
            voice = listener.listen(source)
            com = listener.recognize_google(voice)

    except:
        pass
    return com
def vk():
    command = take()
    if 'happy' in command:
        talk('yes iam happy')
    elif 'what is your name' in command:
        talk('my name is vk 3.7')
    elif 'who created you' in command:
        talk('vishak created me')

    elif 'play' in command:
        song = command.replace('play', '')
        talk('playing' + song)
        pywhatkit.playonyt(song)

    elif 'hai' in command:
        talk('hehehe')

    elif 'how are you' in command:
        talk('iam fine thank you')
    elif 'what is' in command:
        dd = command.replace('what is', '')
        woc = wikipedia.summary(dd, 1)
        talk(woc)

    elif 'time' in command:
        time = datetime.now().strftime('%I:%M %p')
        talk('the time is' + time)
    elif 'can you talk faster' in command:
        new = 180
        on.setProperty("rate", new)
        talk('yes i can talk faster is this fast ok for you vishak')

    elif 'can you speak other languages' in command:
        talk('sorry i dont know other languages,but i can learn')

    elif 'get' in command:
        nic = command.replace('what is', '')
        wac = wikipedia.summary(nic, 1)
        talk(wac)
    elif 'can you change your voice' in command:
        voices = on.getProperty('voices')
        on.setProperty('voice', voices[0].id)
        talk('okay,what about my new voice')
    elif 'wow cool' in command:
        talk('thank you')


    elif 'then tell me something' in command:
        talk('can you please me more romantic vishak,it will be better')



    elif 'who is ' in command:
        who = command.replace('who is', '')
        ohw = wikipedia.summary(who, 1)
        talk(ohw)


while True: vk()


elif 기능을 편집하고 필요에 따라 적절한 텍스트(질문)를 추가하고 대화 블록에 답을 적을 수 있습니다.

Create your own piece of code!
Enjoy <3

좋은 웹페이지 즐겨찾기