add google application credentials
This commit is contained in:
@@ -3,9 +3,11 @@ import os
|
|||||||
import asyncio
|
import asyncio
|
||||||
from asyncio import Queue
|
from asyncio import Queue
|
||||||
import logging
|
import logging
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
from google.cloud import texttospeech
|
from google.cloud import texttospeech
|
||||||
|
|
||||||
|
from .storage import AIStorage
|
||||||
from .compute_task import ComputeTask, ComputeTaskResult, ComputeTaskState, ComputeTaskType
|
from .compute_task import ComputeTask, ComputeTaskResult, ComputeTaskState, ComputeTaskType
|
||||||
from .compute_node import ComputeNode
|
from .compute_node import ComputeNode
|
||||||
|
|
||||||
@@ -31,8 +33,7 @@ class GoogleTextToSpeechNode(ComputeNode):
|
|||||||
super().__init__()
|
super().__init__()
|
||||||
self.node_id = "google_text_to_speech_node"
|
self.node_id = "google_text_to_speech_node"
|
||||||
self.task_queue = Queue()
|
self.task_queue = Queue()
|
||||||
|
self.client: Optional[texttospeech.TextToSpeechClient] = None
|
||||||
self.client = texttospeech.TextToSpeechClient()
|
|
||||||
|
|
||||||
self.language_list = {
|
self.language_list = {
|
||||||
"cnm-CN": {
|
"cnm-CN": {
|
||||||
@@ -86,6 +87,14 @@ class GoogleTextToSpeechNode(ComputeNode):
|
|||||||
}
|
}
|
||||||
self.start()
|
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):
|
def start(self):
|
||||||
async def _run_task_loop():
|
async def _run_task_loop():
|
||||||
while True:
|
while True:
|
||||||
@@ -161,3 +170,11 @@ class GoogleTextToSpeechNode(ComputeNode):
|
|||||||
|
|
||||||
def is_local(self) -> bool:
|
def is_local(self) -> bool:
|
||||||
return False
|
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)
|
||||||
|
|||||||
@@ -59,6 +59,9 @@ class AIOS_Shell:
|
|||||||
user_config.add_user_config("shell.current","last opened target and topic",True,"default@Jarvis")
|
user_config.add_user_config("shell.current","last opened target and topic",True,"default@Jarvis")
|
||||||
proxy.declare_user_config()
|
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:
|
async def _handle_no_target_msg(self,bus:AIBus,msg:AgentMsg) -> bool:
|
||||||
target_id = msg.target.split(".")[0]
|
target_id = msg.target.split(".")[0]
|
||||||
@@ -97,8 +100,13 @@ class AIOS_Shell:
|
|||||||
return False
|
return False
|
||||||
ComputeKernel.get_instance().add_compute_node(open_ai_node)
|
ComputeKernel.get_instance().add_compute_node(open_ai_node)
|
||||||
|
|
||||||
|
try:
|
||||||
google_text_to_speech_node = GoogleTextToSpeechNode.get_instance()
|
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)
|
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()
|
llama_ai_node = LocalLlama_ComputeNode()
|
||||||
await llama_ai_node.start()
|
await llama_ai_node.start()
|
||||||
|
|||||||
Reference in New Issue
Block a user