uezo / aiavatarkit

🥰 Building AI-based conversational avatars lightning fast ⚡️💬
Apache License 2.0
261 stars 22 forks source link

Support Azure Speech Services #24

Closed uezo closed 9 months ago

uezo commented 9 months ago

See the following example to use Azure Speech Services:

import logging
from aiavatar import AIAvatar
from aiavatar.listeners.azurevoicerequest import AzureVoiceRequestListener
from aiavatar.listeners.azurewakeword import AzureWakewordListener

OPENAI_API_KEY = "YOUR_API_KEY"
AZURE_SUBSCRIPTION_KEY = "YOUR_SUBSCRIPTION_KEY"
AZURE_REGION = "japanwest"
VV_URL = "http://127.0.0.1:50021"
VV_SPEAKER = 46

# Configure root logger
logger = logging.getLogger()
logger.setLevel(logging.INFO)
log_format = logging.Formatter("[%(levelname)s] %(asctime)s : %(message)s")
streamHandler = logging.StreamHandler()
streamHandler.setFormatter(log_format)
logger.addHandler(streamHandler)

# Prompt
system_message_content = """あなたは「joy」「angry」「sorrow」「fun」の4つの表情を持っています。
特に表情を表現したい場合は、文章の先頭に[face:joy]のように挿入してください。

例
[face:joy]ねえ、海が見えるよ![face:fun]早く泳ごうよ。
"""

# Create AzureVoiceRequestListener
request_listener = AzureVoiceRequestListener(
    AZURE_SUBSCRIPTION_KEY,
    AZURE_REGION,
    # device_name="BuiltInMicrophoneDevice" # <- Set deviceUID and uncomment to specify the microphone device
)

# Create AIAvatar
app = AIAvatar(
    openai_api_key=OPENAI_API_KEY,
    system_message_content=system_message_content,
    request_listener=request_listener,
    voicevox_url=VV_URL,
    voicevox_speaker_id=VV_SPEAKER,
)

# Create WakewordListener
async def on_wakeword(text):
    logger.info(f"Wakeword: {text}")
    await app.start_chat()

wakeword_listener = AzureWakewordListener(
    AZURE_SUBSCRIPTION_KEY,
    AZURE_REGION,
    wakewords=["こんにちは"],
    on_wakeword=on_wakeword,
    # device_name="BuiltInMicrophoneDevice" # <- Set deviceUID and uncomment to specify the microphone device
)

# Start listening
ww_thread = wakeword_listener.start()
ww_thread.join()