181 lines
4.6 KiB
Python
181 lines
4.6 KiB
Python
"""
|
||
プロパティ定義
|
||
アドオンで使用する設定値やパラメータを定義
|
||
"""
|
||
|
||
import bpy
|
||
from bpy.props import (
|
||
StringProperty,
|
||
IntProperty,
|
||
FloatProperty,
|
||
BoolProperty,
|
||
EnumProperty,
|
||
)
|
||
|
||
# グローバル変数で話者リストをキャッシュ
|
||
_speaker_cache = []
|
||
|
||
|
||
def get_speaker_items(self, context):
|
||
"""キャッシュされた話者一覧を返す"""
|
||
global _speaker_cache
|
||
|
||
if not _speaker_cache:
|
||
# キャッシュが空の場合はデフォルトを返す
|
||
return [('0', 'リロードボタンを押してください', 'VoiceVoxから話者リストを取得')]
|
||
|
||
return _speaker_cache
|
||
|
||
|
||
def update_speaker_cache(host: str = "127.0.0.1", port: int = 50021):
|
||
"""VoiceVox APIから話者リストを取得してキャッシュを更新"""
|
||
global _speaker_cache
|
||
from .voicevox import VoiceVoxAPI
|
||
|
||
items = []
|
||
|
||
try:
|
||
api = VoiceVoxAPI(host, port)
|
||
speakers = api.get_speakers()
|
||
|
||
if speakers:
|
||
for speaker in speakers:
|
||
name = speaker.get('name', 'Unknown')
|
||
styles = speaker.get('styles', [])
|
||
|
||
for style in styles:
|
||
style_name = style.get('name', '')
|
||
style_id = style.get('id', 0)
|
||
|
||
# 表示名: "キャラクター名 (スタイル名)"
|
||
display_name = f"{name} ({style_name})" if style_name else name
|
||
|
||
items.append((
|
||
str(style_id),
|
||
display_name,
|
||
f"Speaker ID: {style_id}",
|
||
))
|
||
|
||
_speaker_cache = items
|
||
return len(items)
|
||
else:
|
||
_speaker_cache = [('0', 'VoiceVoxに接続できません', '')]
|
||
return 0
|
||
|
||
except Exception as e:
|
||
print(f"[VoiceVox] 話者一覧の取得に失敗: {e}")
|
||
import traceback
|
||
traceback.print_exc()
|
||
_speaker_cache = [('0', '接続エラー', str(e))]
|
||
return 0
|
||
|
||
|
||
class VoiceVoxProperties(bpy.types.PropertyGroup):
|
||
"""VoiceVoxプラグインのプロパティ"""
|
||
|
||
# VoiceVox エンジンの設定
|
||
voicevox_host: StringProperty(
|
||
name="VoiceVox Host",
|
||
description="VoiceVoxエンジンのホストアドレス",
|
||
default="127.0.0.1",
|
||
)
|
||
|
||
voicevox_port: IntProperty(
|
||
name="VoiceVox Port",
|
||
description="VoiceVoxエンジンのポート番号",
|
||
default=50021,
|
||
min=1,
|
||
max=65535,
|
||
)
|
||
|
||
# 音声合成の設定
|
||
text: StringProperty(
|
||
name="Text",
|
||
description="音声合成するテキスト",
|
||
default="",
|
||
)
|
||
|
||
speaker: EnumProperty(
|
||
name="Speaker",
|
||
description="話者を選択",
|
||
items=get_speaker_items,
|
||
)
|
||
|
||
# 後方互換性のため残す(内部的にはspeakerを使用)
|
||
speaker_id: IntProperty(
|
||
name="Speaker ID",
|
||
description="話者ID (VoiceVoxのキャラクター)",
|
||
default=0,
|
||
min=0,
|
||
)
|
||
|
||
speed_scale: FloatProperty(
|
||
name="Speed",
|
||
description="話速",
|
||
default=1.0,
|
||
min=0.5,
|
||
max=2.0,
|
||
)
|
||
|
||
pitch_scale: FloatProperty(
|
||
name="Pitch",
|
||
description="音高",
|
||
default=0.0,
|
||
min=-0.15,
|
||
max=0.15,
|
||
)
|
||
|
||
intonation_scale: FloatProperty(
|
||
name="Intonation",
|
||
description="抑揚",
|
||
default=1.0,
|
||
min=0.0,
|
||
max=2.0,
|
||
)
|
||
|
||
volume_scale: FloatProperty(
|
||
name="Volume",
|
||
description="音量",
|
||
default=1.0,
|
||
min=0.0,
|
||
max=2.0,
|
||
)
|
||
|
||
# チャンネル設定
|
||
audio_channel: IntProperty(
|
||
name="Audio Channel",
|
||
description="音声を配置するチャンネル番号",
|
||
default=1,
|
||
min=1,
|
||
max=128,
|
||
)
|
||
|
||
subtitle_channel: IntProperty(
|
||
name="Subtitle Channel",
|
||
description="字幕を配置するチャンネル番号",
|
||
default=2,
|
||
min=1,
|
||
max=128,
|
||
)
|
||
|
||
# リファレンステキストストリップ
|
||
reference_text_strip: StringProperty(
|
||
name="Reference Text Strip",
|
||
description="設定を流用するリファレンステキストストリップの名前",
|
||
default="",
|
||
)
|
||
|
||
# 出力設定
|
||
output_directory: StringProperty(
|
||
name="Output Directory",
|
||
description="音声ファイルの出力先ディレクトリ",
|
||
default="//audio_cache/",
|
||
subtype='DIR_PATH',
|
||
)
|
||
|
||
auto_add_to_sequencer: BoolProperty(
|
||
name="Auto Add to Sequencer",
|
||
description="生成した音声と字幕を自動的にシーケンサーに追加",
|
||
default=True,
|
||
)
|