Skip to content

Commit

Permalink
Merge pull request jsk-ros-pkg#319 from knorth55/load-dialogflow-proj…
Browse files Browse the repository at this point in the history
…ect-id-from-json

[dialogflow_task_executive] load dialogflow project_id from credentials
  • Loading branch information
k-okada committed Dec 31, 2021
2 parents 91888c5 + 1d5541b commit cb90545
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions dialogflow_task_executive/node_scripts/dialogflow_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@

import actionlib
import dialogflow as df
from google.oauth2.service_account import Credentials
from google.protobuf.json_format import MessageToJson
import pprint
import Queue
import rospy
import threading
import uuid
import os

from audio_common_msgs.msg import AudioData
from sound_play.msg import SoundRequest
Expand Down Expand Up @@ -62,8 +62,6 @@ def __ne__(self, state):
class DialogflowClient(object):

def __init__(self):
# project id for google cloud service
self.project_id = rospy.get_param("~project_id")
# language for dialogflow
self.language = rospy.get_param("~language", "ja-JP")

Expand All @@ -72,10 +70,6 @@ def __init__(self):
# sample rate of audio data
self.audio_sample_rate = rospy.get_param("~audio_sample_rate", 16000)

# if GOOLGE_APPLICATION_CREDENTIALS is not set, use google_cloud_credentials_json param
if not "GOOGLE_APPLICATION_CREDENTIALS" in os.environ:
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = rospy.get_param("~google_cloud_credentials_json")

# use TTS feature
self.use_tts = rospy.get_param("~use_tts", True)
self.volume = rospy.get_param('~volume', 1.0)
Expand All @@ -90,9 +84,26 @@ def __init__(self):

self.state = State()
self.session_id = None
self.session_client = df.SessionsClient()
self.queue = Queue.Queue()
self.last_spoken = rospy.Time(0)

credentials_json = rospy.get_param(
'~google_cloud_credentials_json', None)
if credentials_json is None:
rospy.loginfo("Loading credential json from env")
# project id for google cloud service
self.project_id = rospy.get_param("~project_id", None)
self.session_client = df.SessionsClient()
else:
rospy.loginfo("Loading credential json from rosparam")
credentials = Credentials.from_service_account_file(
credentials_json
)
self.project_id = credentials.project_id
self.session_client = df.SessionsClient(
credentials=credentials
)
if self.project_id is None:
rospy.logerr('project ID is not set')

if self.use_tts:
soundplay_action_name = rospy.get_param(
Expand Down

0 comments on commit cb90545

Please sign in to comment.