[Python] Conversation using OpenJTalk and Talk API (up to voice output)

Introduction

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

environment

Windows 10 Python 3.7 OpenJTalk pya3rt (for using talk api)

Preparation

OpenJTalk Speech synthesis software that can also be used from Python. The article here summarizes everything from environment construction to speaking in Python.

Conversation function

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

code

Conversation function

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.

Audio output

Next is the audio output part, but call jtalk.py created in this article.

import jtalk

jtalk.jtalk('Characters you want to speak')

result

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

in conclusion

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.

The site that I used as a reference

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

[Python] Conversation using OpenJTalk and Talk API (up to voice output)
Add conversation function to slack bot (made by python) using Recruit's Talk API
Output product information to csv using Rakuten product search API [Python]
How to get followers and followers from python using the Mastodon API
From Python to using MeCab (and CaboCha)
Procedure to use TeamGant's WEB API (using python)
Output python log to both console and file
Try using ChatWork API and Qiita API in Python
How to set up a Python environment using pyenv
Push notifications from Python to Android using Google's API
Send and receive Gmail via the Gmail API using Python
python input and output
Speech transcription procedure using Python and Google Cloud Speech API
Output to "7-segment LED" using python on Raspberry Pi 3!
Create a simple API just to input and output JSON files ~ Python / Flask edition ~
I want to make a voice changer using Python and SPTK with reference to a famous site
Easy to use Nifty Cloud API with botocore and python
Script to count and stop up to 5 seconds in Python in Blender
Try to make it using GUI and PyQt in Python
Try to bring up a subwindow with PyQt5 and Python
Predict gender from name using Gender API and Pykakasi in Python
Tweet Now Playing to Twitter using the Spotify API. [Python]
I made a Chatbot using LINE Messaging API and Python
Aggregate and analyze product prices using Rakuten Product Search API [Python]
Post to Twitter using Python
Start to Selenium using python
Introduction to discord.py (3) Using voice
Operate Jupyter with REST API to extract and save Python code
[Python] Hit Keras from TensorFlow and TensorFlow from c ++ to speed up execution
Process Splunk execution results using Python and save to a file
Collect product information and process data using Rakuten product search API [Python]
Output search results of posts to a file using Mattermost API
Regularly upload files to Google Drive using the Google Drive API in Python
[Python] I tried to get various information using YouTube Data API!
[Python] I wrote a REST API using AWS API Gateway and Lambda.
I made a Chatbot using LINE Messaging API and Python (2) ~ Server ~
How to install python using anaconda
Python 3.6 on Windows ... and to Xamarin.
Numba to speed up as Python
Data acquisition using python googlemap api
Authentication using tweepy-User authentication and application authentication (Python)
[Python3] Google translate google translate without using api
Output to csv file with Python
Try using Pleasant's API (python / FastAPI)
Cooperation between python module and API
[Code] Module and Python version output
How to use OpenPose's Python API
Try using Python argparse's action API
How to speed up Python calculations
Export and output files in Python
Python logging and dump to json
Selenium and python to open google
Interactively output BPE using python curses
Run Ansible from Python using API
[Python] How to use Typetalk API
[Python] Create API to send Gmail
Challenge to create time axis list report with Toggl API and Python
[Circuit x Python] How to expand and calculate transfer functions using Lcapy
What to do if ipython and python start up with different versions
Development and deployment of REST API in Python using Falcon Web Framework
Sample code to get the Twitter API oauth_token and oauth_token_secret in Python 2.7