I used to make an automatic reply function using Recruit's Talk API when I made my own slackbot. And if you use OpenJTalk, which you recently built an environment, you can actually talk! I thought and tried it. I'm not without friends
Windows 10 Python 3.7 OpenJTalk pya3rt (for using talk api)
OpenJTalk Speech synthesis software that can also be used from Python. The article here summarizes everything from environment construction to speaking in Python.
Talk API It is an API that returns a reply when you send a character string. I referred to Conversation API / Library / Service Summary that can be used with BOT.
Talk API
Recruit Technology is one of the open innovations of machine learning and deep learning technology used in-house as part of open innovation. Other interesting things such as Image Environment API that can create a model to judge the preference of images for A / B testing and Text Suggest API that automatically generates sentences and assists input are released.
From here, you can register your email address and issue an API. Talk API
pya3rt A library called pya3rt that is easy to use from Python is provided. Please install with the following command.
pip install pya3rt
I made the conversation function part a function. message is a string sent to the API and the return value is the conversation response.
import pya3rt
def send_message(message):
apikey = "api key"
client = pya3rt.TalkClient(apikey)
reply_message = client.talk(message)
return reply_message['results'][0]['reply']
The contents of reply_message are like this.
{'status': 0, 'message': 'ok', 'results': [{'perplexity': 0.06766985185966182, 'reply': 'Hello'}]}
I wanted to pull out only the reply part
reply_message['results'][0]['reply']
It was made.
Next is the audio output part, but call jtalk.py
created in this article.
import jtalk
jtalk.jtalk('Characters you want to speak')
The total of these is as follows. It is a flow of receiving a character string from the console ⇒ throwing it to the API ⇒ outputting voice.
import pya3rt
import jtalk
def send_message(message):
apikey = "api key"
client = pya3rt.TalkClient(apikey)
reply_message = client.talk(message)
return reply_message['results'][0]['reply']
if __name__ == "__main__":
while True:
message = input("message : ")
reply = send_message(message)
print(reply)
jtalk.jtalk(result)
Output result. If OpenJTalk is used, the reply (the one without message:) will be output by voice.
message :Hello
Hello
message :It snowed
Do you have a cold?
message :it's cold
I think so, too
message :is not it
That's right
message :Who are you?
I don't have a name yet
It was very easy to implement. Python and API are amazing. After that, if you can recognize voice, you can talk with people and computers.
Summary of conversation APIs, libraries, and services that can be used with BOT Add conversation function to slack bot (made by python) using Recruit's Talk API
Recommended Posts