add google application credentials

This commit is contained in:
wugren
2023-09-22 13:38:44 +08:00
parent b8345eccaf
commit b195e6a6a4
2 changed files with 39 additions and 14 deletions
+19 -2
View File
@@ -3,9 +3,11 @@ import os
import asyncio
from asyncio import Queue
import logging
from typing import Optional
from google.cloud import texttospeech
from .storage import AIStorage
from .compute_task import ComputeTask, ComputeTaskResult, ComputeTaskState, ComputeTaskType
from .compute_node import ComputeNode
@@ -31,8 +33,7 @@ class GoogleTextToSpeechNode(ComputeNode):
super().__init__()
self.node_id = "google_text_to_speech_node"
self.task_queue = Queue()
self.client = texttospeech.TextToSpeechClient()
self.client: Optional[texttospeech.TextToSpeechClient] = None
self.language_list = {
"cnm-CN": {
@@ -86,6 +87,14 @@ class GoogleTextToSpeechNode(ComputeNode):
}
self.start()
def init(self):
user_config = AIStorage.get_instance().get_user_config()
google_application_credentials = user_config.get_value("google_application_credentials")
if google_application_credentials is None:
raise Exception("google_application_credentials is None!")
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = google_application_credentials
self.client = texttospeech.TextToSpeechClient()
def start(self):
async def _run_task_loop():
while True:
@@ -161,3 +170,11 @@ class GoogleTextToSpeechNode(ComputeNode):
def is_local(self) -> bool:
return False
def declare_user_config(self):
if os.getenv("GOOGLE_APPLICATION_CREDENTIALS") is None:
user_config = AIStorage.get_instance().get_user_config()
user_config.add_user_config("google_application_credentials",
"google application credentials, please visit:https://cloud.google.com/text-to-speech/docs/before-you-begin",
False,
None)
+10 -2
View File
@@ -59,6 +59,9 @@ class AIOS_Shell:
user_config.add_user_config("shell.current","last opened target and topic",True,"default@Jarvis")
proxy.declare_user_config()
google_text_to_speech = GoogleTextToSpeechNode.get_instance()
google_text_to_speech.declare_user_config()
async def _handle_no_target_msg(self,bus:AIBus,msg:AgentMsg) -> bool:
target_id = msg.target.split(".")[0]
@@ -97,8 +100,13 @@ class AIOS_Shell:
return False
ComputeKernel.get_instance().add_compute_node(open_ai_node)
google_text_to_speech_node = GoogleTextToSpeechNode.get_instance()
ComputeKernel.get_instance().add_compute_node(google_text_to_speech_node)
try:
google_text_to_speech_node = GoogleTextToSpeechNode.get_instance()
google_text_to_speech_node.init()
ComputeKernel.get_instance().add_compute_node(google_text_to_speech_node)
except Exception as e:
logger.error(f"google text to speech node initial failed! {e}")
return False
llama_ai_node = LocalLlama_ComputeNode()
await llama_ai_node.start()