Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Yoshida branch #11

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Unity/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
.env
credentials.json
token.json
63 changes: 0 additions & 63 deletions Unity/call_function.py

This file was deleted.

53 changes: 34 additions & 19 deletions Unity/create_voice.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,48 @@
# 親ディレクトリをPythonのパスに追加
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..')))
# from sd_2410.audio.register_time import register_and_responce
from socketServer import getString_socket
from sd_2410.Unity.socket_server import getString_socket

# ずんだもんの話者ID
speaker_id = 3
#speaker_id = 67
while 1:
# while 1:
# #ここにLLMからの応答データを入れる
# text = getString_socket()

# # 音声合成用クエリを作成
# query_payload = {'text': text, 'speaker': speaker_id}
# query_res = requests.post("http://127.0.0.1:50021/audio_query", params=query_payload)
# query_res.raise_for_status()
# audio_query = query_res.json()

# # 音声合成を実行して音声データを生成
# synthesis_res = requests.post(
# "http://127.0.0.1:50021/synthesis", #ローカルでやるとき
# params={'speaker': speaker_id},
# json=audio_query
# )

# synthesis_res.raise_for_status()

# # 音声ファイルを保存して再生(絶対パス)
# with open("C:/Users/renta/Joyman/Assets/Audio/bando.wav", "wb") as f:
# f.write(synthesis_res.content)

# # 文字ファイルを保存(絶対パス)
# with open("C:/Users/renta/Joyman/Assets/Text/responce.txt", "w",encoding="utf-8") as f:
# f.write(text)

# print("音声・文字ファイルが生成されました!")


def create_voice(text):
#ここにLLMからの応答データを入れる
text = getString_socket()
#text = "おはようございますですわ"

# 音声合成用クエリを作成
query_payload = {'text': text, 'speaker': speaker_id}
query_res = requests.post("http://127.0.0.1:50021/audio_query", params=query_payload)
#query_res = requests.post("http://10.0.0.194:50021/audio_query", params=query_payload) #VPN接続して
query_res.raise_for_status()
audio_query = query_res.json()

Expand All @@ -32,24 +61,10 @@
json=audio_query
)

# synthesis_res = requests.post(
# "http://10.0.0.194:50021/synthesis", #リクエスト投げるときはyotchiのPCのIPアドレスにしてください
# params={'speaker': speaker_id},
# json=audio_query
# )

synthesis_res.raise_for_status()

# # 音声ファイルを保存して再生
# with open("sd_2410/Unity/Assets/resouce/zundamon_voice.wav", "wb") as f:
# f.write(synthesis_res.content)

# # 文字ファイルを保存
# with open("sd_2410/Unity/Assets/resouce/responce.txt", "w",encoding="utf-8") as f:
# f.write(text)

# 音声ファイルを保存して再生(絶対パス)
with open("C:/Users/renta/Joyman/Assets/Audio/bando.wav", "wb") as f:
with open("C:/Users/renta/Joyman/Assets/Audio/abando.wav", "wb") as f:
f.write(synthesis_res.content)

# 文字ファイルを保存(絶対パス)
Expand Down
70 changes: 70 additions & 0 deletions Unity/google_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
from datetime import datetime, timezone
import os
from google.auth.transport.requests import Request
from google.oauth2.credentials import Credentials
from google_auth_oauthlib.flow import InstalledAppFlow
from googleapiclient.discovery import build

# Google Calendar APIのスコープ(読み書き権限)
SCOPES = ["https://www.googleapis.com/auth/calendar"]
TOKEN_PATH=f"{os.path.dirname(os.path.abspath(__file__))}/token.json"
CRED_PATH=f"{os.path.dirname(os.path.abspath(__file__))}/credentials.json"

def get_calendar_service():
creds = None
# 既存のトークンファイルがあれば読み込む(トークンは認証情報を保存するためのもの)
if os.path.exists(TOKEN_PATH):
creds = Credentials.from_authorized_user_file(TOKEN_PATH, SCOPES)
# 有効な認証情報がない場合、再認証を実行
if not creds or not creds.valid:
if creds and creds.expired and creds.refresh_token:
# トークンの期限が切れている場合、リフレッシュ
creds.refresh(Request())
else:
# 初回認証、もしくはトークンがない場合に認証フローを開始
flow = InstalledAppFlow.from_client_secrets_file(CRED_PATH, SCOPES)
creds = flow.run_local_server(port=0)
# 認証情報をtoken.jsonに保存して次回以降再利用できるようにする
with open(TOKEN_PATH, "w") as token:
token.write(creds.to_json())
# Google Calendar APIサービスのインスタンスを作成
service = build("calendar", "v3", credentials=creds)
return service

#カレンダーに予定登録
def register_event(summary:str, start:str, end:str):
service=get_calendar_service()
# イベントの詳細情報
event = {
'summary': summary, # イベントのタイトル
'start': { # イベント開始日時(日本時間)
'dateTime': start,
'timeZone': 'Asia/Tokyo'
},
'end': { # イベント終了日時(日本時間)
'dateTime': end,
'timeZone': 'Asia/Tokyo'
},
}
# イベントをGoogleカレンダーに追加
created_event = service.events().insert(calendarId='primary', body=event).execute()
print('Event created: %s' % created_event.get('htmlLink')) # 作成したイベントのリンクを出力
return "登録成功"


def get_events():
service = get_calendar_service()
# 今から1週間分のイベントを取得する
now = datetime.now().isoformat() + 'Z'
events_result = service.events().list(
calendarId='primary', timeMin=now,
maxResults= 3, singleEvents=True,
orderBy='startTime').execute()
events = events_result.get('items', [])
if not events:
print('イベントが取得できませんでした')
return "イベントが取得できませんでした"
for event in events:
scedule = event['start'].get('dateTime', event['start'].get('date'))
print(scedule, event['summary'])
return events
File renamed without changes.
File renamed without changes.
Loading