-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
61dbb93
commit d1270ad
Showing
9 changed files
with
351 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
# ZundaGPT | ||
# | ||
# COEIROINK APIクラス | ||
# | ||
# Copyright (c) 2024 led-mirage | ||
# このソースコードは MITライセンス の下でライセンスされています。 | ||
# ライセンスの詳細については、このプロジェクトのLICENSEファイルを参照してください。 | ||
|
||
import json | ||
|
||
import requests | ||
|
||
class CoeiroinkApi: | ||
DEFAULT_SERVER = "http://127.0.0.1:50032" | ||
server = DEFAULT_SERVER | ||
|
||
# ステータスを取得する | ||
@staticmethod | ||
def get_status(print_error=False) -> str: | ||
try: | ||
response = requests.get(f"{CoeiroinkApi.server}/") | ||
response.raise_for_status() | ||
return response.json()["status"] | ||
except Exception as err: | ||
if print_error: | ||
print(err) | ||
return None | ||
|
||
# 話者リストを取得する | ||
@staticmethod | ||
def get_speakers(print_error=False) -> {}: | ||
try: | ||
response = requests.get(f"{CoeiroinkApi.server}/v1/speakers") | ||
response.raise_for_status() | ||
return response.json() | ||
except Exception as err: | ||
if print_error: | ||
print(err) | ||
return None | ||
|
||
# スタイルIDから話者情報を取得する | ||
@staticmethod | ||
def get_speaker_info(styleId: int, print_error=False) -> {}: | ||
try: | ||
post_params = {"styleId": styleId} | ||
response = requests.post(f"{CoeiroinkApi.server}/v1/style_id_to_speaker_meta", params=post_params) | ||
response.raise_for_status() | ||
return response.json() | ||
except Exception as err: | ||
if print_error: | ||
print(err) | ||
return None | ||
|
||
# テキストの読み上げ用データを取得する | ||
@staticmethod | ||
def estimate_prosody(text: str, print_error=False) -> {}: | ||
try: | ||
post_params = {"text": text} | ||
response = requests.post(f"{CoeiroinkApi.server}/v1/estimate_prosody", data=json.dumps(post_params)) | ||
response.raise_for_status() | ||
return response.json() | ||
except Exception as err: | ||
if print_error: | ||
print(err) | ||
return None | ||
|
||
# 音声データを生成する | ||
@staticmethod | ||
def synthesis(speaker: {}, text: str, prosody: {}, | ||
speedScale = 1, volumeScale = 1, pitchScale = 0, intonationScale = 1, | ||
prePhonemeLength = 0.1, postPhonemeLength = 0.1, outputSamplingRate = 24000, print_error=False) -> bytes: | ||
post_params = { | ||
"speakerUuid": speaker["speakerUuid"], | ||
"styleId": speaker["styleId"], | ||
"text": text, | ||
"prosodyDetail": prosody["detail"], | ||
"speedScale": speedScale, | ||
"volumeScale": volumeScale, | ||
"pitchScale": pitchScale, | ||
"intonationScale": intonationScale, | ||
"prePhonemeLength": prePhonemeLength, | ||
"postPhonemeLength": postPhonemeLength, | ||
"outputSamplingRate": outputSamplingRate | ||
} | ||
try: | ||
response = requests.post(f"{CoeiroinkApi.server}/v1/synthesis", data=json.dumps(post_params)) | ||
response.raise_for_status() | ||
return response.content | ||
except Exception as err: | ||
if print_error: | ||
print(err) | ||
return None | ||
|
||
# 音声データを生成する | ||
@staticmethod | ||
def get_wave_data(styleId: int, text: str, | ||
speedScale = 1, volumeScale = 1, pitchScale = 0, intonationScale = 1, | ||
prePhonemeLength = 0.1, postPhonemeLength = 0.1, outputSamplingRate = 24000, print_error=False) -> bytes: | ||
|
||
speaker = CoeiroinkApi.get_speaker_info(styleId) | ||
if speaker is None: | ||
return None | ||
|
||
prosody = CoeiroinkApi.estimate_prosody(text) | ||
if prosody is None: | ||
return None | ||
|
||
return CoeiroinkApi.synthesis(speaker, text, prosody, | ||
speedScale, volumeScale, pitchScale, intonationScale, | ||
prePhonemeLength, postPhonemeLength, outputSamplingRate, print_error) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# COEIROINK キャラクターリスト | ||
|
||
| SpeakerUuid | StyleId | キャラクター | スタイル | | ||
|-------------|---------|--------------|----------| | ||
| 292ea286-3d5f-f1cc-157c-66462a6a9d08 | 1 | MANA | のーまる | | ||
| 292ea286-3d5f-f1cc-157c-66462a6a9d08 | 7 | MANA | いっしょうけんめい | | ||
| 292ea286-3d5f-f1cc-157c-66462a6a9d08 | 40 | MANA | ごきげん | | ||
| 292ea286-3d5f-f1cc-157c-66462a6a9d08 | 45 | MANA | どやがお | | ||
| 2932eb06-e388-45bf-a6ba-dbc66a48961e | 41 | MANA+ | ふくれっつら | | ||
| 2932eb06-e388-45bf-a6ba-dbc66a48961e | 42 | MANA+ | しょんぼり | | ||
| 2932eb06-e388-45bf-a6ba-dbc66a48961e | 43 | MANA+ | ないしょばなし | | ||
| 2932eb06-e388-45bf-a6ba-dbc66a48961e | 44 | MANA+ | ひっさつわざ | | ||
| 3c37646f-3881-5374-2a83-149267990abc | 0 | つくよみちゃん | れいせい | | ||
| 3c37646f-3881-5374-2a83-149267990abc | 5 | つくよみちゃん | おしとやか | | ||
| 3c37646f-3881-5374-2a83-149267990abc | 6 | つくよみちゃん | げんき | |
Oops, something went wrong.