Forced Alignmentクイックスタート

Forced Alignment APIを使用して、テキストをオーディオにアラインメントする方法を学びます。

このガイドでは、Forced Alignment APIを使用してテキストをオーディオにアラインメントする方法を説明します。

Forced Alignment APIを使用する

1

APIキーを作成する

ダッシュボードでAPIキーを作成し、安全にAPIへアクセスするために使用します。

キーは管理されたシークレットとして保存し、好みに応じて.envファイルによる環境変数として、またはアプリの設定で直接SDKに渡してください。

.env
ELEVENLABS_API_KEY=<your_api_key_here>
2

SDKをインストールする

dotenvライブラリも使用して、環境変数からAPIキーを読み込みます。

pip install elevenlabs
pip install python-dotenv
3

APIリクエストを送信する

使用する言語に応じて、example.pyまたはexample.mtsという名前の新しいファイルを作成し、次のコードを追加します。

# example.py
import os
from io import BytesIO
from elevenlabs.client import ElevenLabs
import requests
from dotenv import load_dotenv
load_dotenv()
elevenlabs = ElevenLabs(
api_key=os.getenv("ELEVENLABS_API_KEY"),
)
audio_url = (
"https://storage.googleapis.com/eleven-public-cdn/audio/marketing/nicole.mp3"
)
response = requests.get(audio_url)
audio_data = BytesIO(response.content)
# Perform the text-to-speech conversion
transcription = elevenlabs.forced_alignment.create(
file=audio_data,
text="With a soft and whispery American accent, I'm the ideal choice for creating ASMR content, meditative guides, or adding an intimate feel to your narrative projects."
)
print(transcription)

次に、実行します。

python example.py

オーディオファイルの文字起こしと正確なタイムスタンプがコンソールに表示されます。

次のステップ