电报漫游器,在消息中表达您的情绪

你好!



在本文中,我将描述仍在运行的电报机器人。



该机器人的创建原因,目的和技能



实际上,一个人会使用各种声音来表达自己的情感和关系。但是几乎所有的人工智能系统和语音助手都是“太智能”的。他们只是丢弃情感声音,不理解并且不能正确使用感叹词。因此,我创建了一个漫游器,它打开了自然​​语音的可能性,充满嗡嗡声,吱吱声,抽泣声,咆哮声和其他一百种情感语调和半音。

我想开发的算法将在商业领域工作,例如,跟踪客户的情绪状态并指导算法的分支以防止其可能采取的行动。情绪是行为的首要调节器,通过言语语调或(例如)轻笑,很容易跟踪用户的困惑和刺激,并在用户开始诅咒和要求之前做出反应。

您还可以给语音助理自己更多的“人性化”。他们可能在长时间的演讲或咧开嘴笑之前清嗓子,而不是用标准的声音解释这是个玩笑。

在医学实践中,该程序将帮助确定无法说清楚话的患者的状况,并通过个人抽泣来指导工作人员进行治疗程序。它可以应用于某些类型的疾病,例如自闭症和阅读障碍。

在即时通讯工具中,除了标准表情符号以外或与标准表情符号不同,该机器人还将通过网络平等地传达情感和关系。

作为实验和开发的平台,我使用Telegram Messenger。

当前,@ YouToneBot将情感声音返回到标准笑脸。

将来,计划教导机器人执行相反的操作,即向声音发出“表情符号”。



最终会是什么样?



他将能够发送语音消息,发出微笑,他也可以在聊天中做到这一点!您甚至不必转移消息,只需在消息中写上他的名字,然后再写您的消息即可。



图片

图片

图片

代码



, , . , , .

Python, PyTelegramBotApi.

, . , , , .. PyTelegramBotApi send_voice() id , message_handler() message.voice.file_id.

, : JSON , , id .

, , id, . , "python ", , id .

:



{
    "emoji1": "voice_id1",
    "emoji2": "voice_id2",
    "emoji3": "voice_id3",
    "emoji4": "voice_id4",
    "emoji5": "voice_id5",
    "emoji6": "voice_id6",
}
#-   ,  "emoji" == ~


.



.

YouTone(), .

def init(self) TOKEN, VOICE_SOUNDS

TOKEN

VOICE_SOUNDS — , id #

, init, self.BOT,



TL.TeleBot(self.TOKEN)


, .

, 3 ,

LS_handler()

start_handler() — (/start /get)

local_lerning()

LS_handler() echo



LS_handler()
def LS_handler(self):
    @self.BOT.message_handler(content_types=['text'])
    def send_text(message):
        def msg(message_text):
            self.BOT.send_message(message.chat.id, str(message_text))
        msg(message.text)


start_handler() /start



start_handler()
def start_handler(self):
    @self.BOT.message_handler(commands=['start', "get"])
    def commands(message):
        if message.text == "/start":
            self.BOT.send_message(message.chat.id, '.      ')


local_lerning(). , , , .

, tkinter. tkitner , , tkitner " ", " ", ( ):



id



3 ,

window_smile() — tkitner

bot_work() — , .

save_sound() — id



, window_smile()



window_smile()
def window_smile():#    local_lerning()
    self.root = Tk()
    self.root.geometry("500x500")
    self.smile_tkinter = Label(text=self.AUDIO_SOUNDS_ITEMS[self.index][0],font='Times 30')
    self.open_sound = Button(text=" ",font='Times 10',command=lambda: webbrowser.open(url=r"/////.ogg"))
    self.Y_or_N = Button(text=" ",font='Times 15',command=save_sound)
    self.info = Label(text="""\n\n\n\n\n\n\n  , ,\n ,\n  ' ',\n  ,\n   ,\n ,\n   .""",font="Consolas 11")
    self.smile_tkinter.pack()
    self.open_sound.pack()
    self.Y_or_N.pack()
    self.info.pack()
    self.root.mainloop() 


bot_work() , , "/////.ogg",



bot_work()
def bot_work():
    @self.BOT.message_handler(content_types=['text',"voice"])
    def send_text(message):
        def msg(message_text):
            self.BOT.send_message(message.chat.id, str(message_text))
        self.smile_now = self.SOUNDS_DB[self.index][0]
        self.smile_tkinter.config(text=self.smile_now)

        try:
            self.id_voice = message.voice.file_id
            self.voice_info = self.BOT.get_file(file_id=self.id_voice)
            self.voice_file = requests.get('https://api.telegram.org/file/bot{0}/{1}'.format(self.TOKEN, self.voice_info.file_path)).content

        except BaseException as e:
            print(e)
        else:
            with open("/////.ogg", "wb") as f:
                f.write(self.voice_file)


get_file(), id ( ), id requests, .

id , self.voice_id.



save_sound()
def save_sound():

    self.voices_good.update({self.smile_now:str(self.id_voice)})
    self.index += 1
    self.smile_now = self.SMILES_DB[self.index][0]

    self.smile_tkinter.config(text=self.smile_now)
    with open("data.txt","w",encoding="utf-8") as f:
        f.write(str(self.voices_good))


" ".

.

, self.index, , .. self.SMILES_DB



local_lerning(), 2 ,

window_smile() bot_work().

threading.



from threading import Thread
th1 = Thread(target=window_smile)
th1.start()
th2 = Thread(target=bot_work)
th2.start()


local_lerning()
def local_lerning(self):
    from threading import Thread
    self.smile_now = None
    self.index = 0
    self.id_voice = None
    self.voices_good = {

    }
    self.smile_tkinter = None

    def save_sound():

        self.voices_good.update({self.smile_now:str(self.id_voice)})
        self.index += 1
        self.smile_now = self.AUDIO_SOUNDS_ITEMS[self.index][0]

        self.smile_tkinter.config(text=self.smile_now)
        with open("data.txt","w",encoding="utf-8") as f:
            f.write(str(self.voices_good))

    def window_smile():
        self.root = Tk()
        self.root.geometry("500x500")
        self.smile_tkinter = Label(text=self.AUDIO_SOUNDS_ITEMS[self.index][0],font='Times 30')
        self.open_sound = Button(text=" ",font='Times 10',command=lambda: webbrowser.open(url=r"C:\Program Files\JetBrains\projects\telegram\voice.ogg"))
        self.Y_or_N = Button(text=" ",font='Times 15',command=save_sound)
        self.info = Label(text="""\n\n\n\n\n\n\n  , ,\n ,\n  ' ',\n  ,\n   ,\n ,\n   .""",font="Consolas 11")
        self.smile_tkinter.pack()
        self.open_sound.pack()
        self.Y_or_N.pack()
        self.info.pack()
        self.root.mainloop()

    def bot_work():
        @self.BOT.message_handler(content_types=['text',"voice"])
        def send_text(message):
            def msg(message_text):
                self.BOT.send_message(message.chat.id, str(message_text))

            def snd_doc(name_doc):
                self.BOT.send_document(message.chat.id, open(name_doc, "rb"))

            self.smile_now = self.AUDIO_SOUNDS_ITEMS[self.index][0]
            self.smile_tkinter.config(text=self.smile_now)

            try:
                self.id_voice = message.voice.file_id
                self.voice_info = self.BOT.get_file(file_id=self.id_voice)
                self.voice_file = requests.get('https://api.telegram.org/file/bot{0}/{1}'.format(self.TOKEN, self.voice_info.file_path)).content

            except BaseException as e:
                print(": ",e)
            else:
                with open("voice.ogg", "wb") as f:
                    f.write(self.voice_file)

    th1 = Thread(target=window_smile)
    th1.start()
    th2 = Thread(target=bot_work)
    th2.start()


.

图片



, . .

, .



. , inline.

, , , , , .



message_list = list(message.text)
is_send = False
for word in message_list:
    if word in self.VOICE_SOUNDS:
        if self.VOICE_SOUNDS[word]:
            snd_voice(voice_id=self.VOICE_SOUNDS[word])
            print("smile has been found")
            is_send = True
            break
if not is_send:
    print("smile has been not found")


LS_handler()
def LS_handler(self):
    @self.BOT.message_handler(content_types=['text'])
    def send_text(message):
        def msg(message_text):
            self.BOT.send_message(message.chat.id, str(message_text))

        def snd_doc(name_doc):
            self.BOT.send_document(message.chat.id, open(name_doc, "rb"))
        def snd_voice(voice_id: str):
            self.BOT.send_voice(message.chat.id,voice=voice_id)

        message_list = list(message.text)
        is_send = False
        for word in message_list:
            if word in self.VOICE_SOUNDS:
                if self.VOICE_SOUNDS[word]:
                    snd_voice(voice_id=self.VOICE_SOUNDS[word])
                    is_send = True
                    break
        if not is_send:
            msg("      


LS_handler(), , inline_handler()



inline

inline , , , -



inline_handler()
def inline_handler(self):
    @self.BOT.inline_handler(lambda query: len(query.query) > 0)
    def query_text(query):
        message_list = list(query.query)
        #    ,   ,   ;)
        output_msg = [types.InlineQueryResultArticle(
            id="1",
            title="      ",
            input_message_content=types.InputTextMessageContent(message_text="     ")
        )]
        is_send = False
        id_now = 1#id  
        for word in message_list:
            try:
                self.VOICE_SOUNDS[word]
            except KeyError:
                pass
            else:
                if self.VOICE_SOUNDS[word]:
                    if is_send == False:
                        output_msg = []
                    is_send = True
                    if not word in [i.title for i in output_msg]:#       ,    ;)
                        output_msg.append(types.InlineQueryResultCachedVoice(
                            id=str(id_now),
                            voice_file_id=self.VOICE_SOUNDS[word],
                            title=str(word),
                            caption=query.query
                        ))
                    else:
                        pass#           
                    id_now +=1 #    id  
        self.BOT.answer_inline_query(query.id, output_msg)


, , — .

.. , , ( break), , . .



inline



图片



, , .

@YouToneBot , , , .. .

!




All Articles