Skip to content

Commit

Permalink
ユーザー辞書の単語の一覧を返すAPIを追加 (#334)
Browse files Browse the repository at this point in the history
* 単語の一覧を返すAPIを追加

* 関数名変更
  • Loading branch information
takana-v authored Feb 20, 2022
1 parent b8acc1c commit 6e2d4f8
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions run.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,19 @@
Speaker,
SpeakerInfo,
SupportedDevicesInfo,
UserDictWord,
)
from voicevox_engine.morphing import synthesis_morphing
from voicevox_engine.morphing import (
synthesis_morphing_parameter as _synthesis_morphing_parameter,
)
from voicevox_engine.preset import Preset, PresetLoader
from voicevox_engine.synthesis_engine import SynthesisEngineBase, make_synthesis_engines
from voicevox_engine.user_dict import apply_word, user_dict_startup_processing
from voicevox_engine.user_dict import (
apply_word,
read_dict,
user_dict_startup_processing,
)
from voicevox_engine.utility import (
ConnectBase64WavesException,
connect_base64_waves,
Expand Down Expand Up @@ -537,7 +542,24 @@ def speaker_info(speaker_uuid: str, core_version: Optional[str] = None):
ret_data = {"policy": policy, "portrait": portrait, "style_infos": style_infos}
return ret_data

@app.post("/user_dict", tags=["その他"])
@app.get("/user_dict", response_model=Dict[int, UserDictWord], tags=["ユーザー辞書"])
def get_user_dict_words():
"""
ユーザ辞書に登録されている単語の一覧を返します。
単語の表層形(surface)は正規化済みの物を返します。
Returns
-------
Dict[int, UserDictWord]
単語のIDとその詳細
"""
try:
return read_dict().words
except Exception:
traceback.print_exc()
raise HTTPException(status_code=422, detail="辞書の読み込みに失敗しました。")

@app.post("/user_dict", status_code=204, tags=["ユーザー辞書"])
def add_user_dict_word(surface: str, pronunciation: str, accent_type: int):
"""
ユーザ辞書に言葉を追加します。
Expand Down

0 comments on commit 6e2d4f8

Please sign in to comment.