非公式のイレブンラボ音声合成の安らかなクライアント。
私は11のenlabsとは関係ありません。APIアクセスを備えたアカウントが必要です。
すべての著作権、商標、ロゴ、および資産は、それぞれの所有者の財産です。
NugetからパッケージElevenLabs-DotNetをインストールします。コマンドライン経由の方法は次のとおりです。
Install-Package ElevenLabs - DotNet dotnet add package ElevenLabs-DotNet
Unity Game Engineで11の葉を使用したいですか? OpenUPMでUnityパッケージをご覧ください:
APIキーを提供するには、優先順位の順に3つの方法があります。
var api = new ElevenLabsClient ( "yourApiKey" ) ;または、 ElevenLabsAuthenticationオブジェクトを手動で作成します
var api = new ElevenLabsClient ( new ElevenLabsAuthentication ( "yourApiKey" ) ) ; 現在のディレクトリのデフォルトでは、デフォルトでは、 .elevenlabsでAPIキーを構成ファイルからロードしようとします。
構成ファイルを作成するには、 .elevenlabsという名前の新しいテキストファイルを作成し、行を含みます。
{
"apiKey" : " yourApiKey " ,
}認証で静的メソッドを呼び出すことにより、既知のパスでファイルを直接ロードすることもできます。
var api = new ElevenLabsClient ( ElevenLabsAuthentication . LoadFromDirectory ( "your/path/to/.elevenlabs" ) ) ; ; システムの環境変数を使用して、使用するAPIキーを指定します。
ELEVEN_LABS_API_KEYを使用します。 var api = new ElevenLabsClient ( ElevenLabsAuthentication . LoadFromEnv ( ) ) ;フロントエンドアプリに直接直接evenlabs-dotnetまたはcom.rest.elevenlabsパッケージを使用すると、APIキーやその他の機密情報が公開される場合があります。このリスクを緩和するには、フロントエンドアプリに代わって11枚のリクエストを行う中間APIを設定することをお勧めします。このライブラリは、フロントエンドと中間ホストの両方のホスト構成に使用して、ElevenLabs APIとの安全な通信を確保できます。
フロントエンドの例では、希望するOAuthプロバイダーを使用してユーザーを安全に認証する必要があります。ユーザーが認証されたら、バックエンドのAPIキーとカスタム認証トークンを交換します。
次の手順に従ってください:
ElevenLabsAuthenticationオブジェクトを作成し、カスタムトークンを渡します。ElevenLabsClientSettingsオブジェクトを作成し、中間APIが配置されているドメインを指定します。authおよびsettingsオブジェクトをElevenLabsClientコンストラクターに渡します。フロントエンドをセットアップする方法の例は次のとおりです。
var authToken = await LoginAsync ( ) ;
var auth = new ElevenLabsAuthentication ( authToken ) ;
var settings = new ElevenLabsClientSettings ( domain : "api.your-custom-domain.com" ) ;
var api = new ElevenLabsClient ( auth , settings ) ;このセットアップにより、フロントエンドアプリケーションは、ElevenLabs-DotNet-Proxyを使用するバックエンドと安全に通信し、リクエストをElevenLabs APIに転送します。これにより、ElevenLabs APIキーやその他の機密情報がプロセス全体で安全なままになることが保証されます。
この例では、新しいASP.NETコアWebアプリでElevenLabsProxyStartupセットアップして使用する方法を示します。プロキシサーバーは、APIキーやその他の機密情報が安全であることを確認するために、ElevenLabs APIへの認証と転送リクエストを処理します。
Install-Package ElevenLabs-DotNet-Proxydotnet add package ElevenLabs-DotNet-Proxy<PackageReference Include="ElevenLabs-DotNet-Proxy" />AbstractAuthenticationFilterから継承する新しいクラスを作成し、 ValidateAuthentication法をオーバーライドします。これにより、内部サーバーに対するユーザーセッショントークンを確認するために使用するIAuthenticationFilterが実装されます。Program.csでは、 ElevenLabsProxyStartup.CreateWebApplicationメソッドを呼び出して、カスタムAuthenticationFilterタイプ引数として渡すことにより、新しいプロキシWebアプリケーションを作成します。ElevenLabsAuthenticationとElevenLabsClientSettingsを作成します。 public partial class Program
{
private class AuthenticationFilter : AbstractAuthenticationFilter
{
public override async Task ValidateAuthenticationAsync ( IHeaderDictionary request )
{
await Task . CompletedTask ; // remote resource call
// You will need to implement your own class to properly test
// custom issued tokens you've setup for your end users.
if ( ! request [ "xi-api-key" ] . ToString ( ) . Contains ( TestUserToken ) )
{
throw new AuthenticationException ( "User is not authorized" ) ;
}
}
}
public static void Main ( string [ ] args )
{
var auth = ElevenLabsAuthentication . LoadFromEnv ( ) ;
var client = new ElevenLabsClient ( auth ) ;
ElevenLabsProxyStartup . CreateWebApplication < AuthenticationFilter > ( args , client ) . Run ( ) ;
}
}プロキシサーバーをセットアップすると、エンドユーザーは、ElevenLabs APIに直接ではなく、プロキシAPIに認証されたリクエストを作成できるようになりました。プロキシサーバーは、APIキーやその他の機密情報が安全であることを確認するために、ElevenLabs APIへの認証と転送リクエストを処理します。
テキストをスピーチに変換します。
var api = new ElevenLabsClient ( ) ;
var text = "The quick brown fox jumps over the lazy dog." ;
var voice = ( await api . VoicesEndpoint . GetAllVoicesAsync ( ) ) . FirstOrDefault ( ) ;
var request = new TextToSpeechRequest ( voice , text ) ;
var voiceClip = await api . TextToSpeechEndpoint . TextToSpeechAsync ( request ) ;
await File . WriteAllBytesAsync ( $ " { voiceClip . Id } .mp3" , voiceClip . ClipData . ToArray ( ) ) ; テキストをスピーチにストリーミングします。
var api = new ElevenLabsClient ( ) ;
var text = "The quick brown fox jumps over the lazy dog." ;
var voice = ( await api . VoicesEndpoint . GetAllVoicesAsync ( ) ) . FirstOrDefault ( ) ;
string fileName = "myfile.mp3" ;
using var outputFileStream = File . OpenWrite ( fileName ) ;
var request = new TextToSpeechRequest ( voice , text ) ;
var voiceClip = await api . TextToSpeechEndpoint . TextToSpeechAsync ( request ,
partialClipCallback : async ( partialClip ) =>
{
// Write the incoming data to the output file stream.
// Alternatively you can play this clip data directly.
await outputFileStream . WriteAsync ( partialClip . ClipData ) ;
} ) ;ユーザーまたはイレブンラブによって作成された声へのアクセス。
Public Voice Libraryに共有声のリストを取得します。
var api = new ElevenLabsClient ( ) ;
var results = await ElevenLabsClient . SharedVoicesEndpoint . GetSharedVoicesAsync ( ) ;
foreach ( var voice in results . Voices )
{
Console . WriteLine ( $ " { voice . OwnerId } | { voice . VoiceId } | { voice . Date } | { voice . Name } " ) ;
} アカウントで利用可能なすべての利用可能な声のリストを取得します。
var api = new ElevenLabsClient ( ) ;
var allVoices = await api . VoicesEndpoint . GetAllVoicesAsync ( ) ;
foreach ( var voice in allVoices )
{
Console . WriteLine ( $ " { voice . Id } | { voice . Name } | similarity boost: { voice . Settings ? . SimilarityBoost } | stability: { voice . Settings ? . Stability } " ) ;
} グローバルなデフォルトの音声設定を取得します。
var api = new ElevenLabsClient ( ) ;
var result = await api . VoicesEndpoint . GetDefaultVoiceSettingsAsync ( ) ;
Console . WriteLine ( $ "stability: { result . Stability } | similarity boost: { result . SimilarityBoost } " ) ; var api = new ElevenLabsClient ( ) ;
var voice = await api . VoicesEndpoint . GetVoiceAsync ( "voiceId" ) ;
Console . WriteLine ( $ " { voice . Id } | { voice . Name } | { voice . PreviewUrl } " ) ; 特定の音声の設定を編集します。
var api = new ElevenLabsClient ( ) ;
var success = await api . VoicesEndpoint . EditVoiceSettingsAsync ( voice , new VoiceSettings ( 0.7f , 0.7f ) ) ;
Console . WriteLine ( $ "Was successful? { success } " ) ; var api = new ElevenLabsClient ( ) ;
var labels = new Dictionary < string , string >
{
{ "accent" , "american" }
} ;
var audioSamplePaths = new List < string > ( ) ;
var voice = await api . VoicesEndpoint . AddVoiceAsync ( "Voice Name" , audioSamplePaths , labels ) ; var api = new ElevenLabsClient ( ) ;
var labels = new Dictionary < string , string >
{
{ "age" , "young" }
} ;
var audioSamplePaths = new List < string > ( ) ;
var success = await api . VoicesEndpoint . EditVoiceAsync ( voice , audioSamplePaths , labels ) ;
Console . WriteLine ( $ "Was successful? { success } " ) ; var api = new ElevenLabsClient ( ) ;
var success = await api . VoicesEndpoint . DeleteVoiceAsync ( voiceId ) ;
Console . WriteLine ( $ "Was successful? { success } " ) ; サンプルへのアクセスは、声をクローズするときに作成されます。
var api = new ElevenLabsClient ( ) ;
var voiceClip = await api . VoicesEndpoint . DownloadVoiceSampleAsync ( voice , sample ) ;
await File . WriteAllBytesAsync ( $ " { voiceClip . Id } .mp3" , voiceClip . ClipData . ToArray ( ) ) ; var api = new ElevenLabsClient ( ) ;
var success = await api . VoicesEndpoint . DeleteVoiceSampleAsync ( voiceId , sampleId ) ;
Console . WriteLine ( $ "Was successful? { success } " ) ;ダブは、指定された言語にオーディオまたはビデオファイルを提供しました。
var api = new ElevenLabsClient ( ) ;
// from URI
var request = new DubbingRequest ( new Uri ( "https://youtu.be/Zo5-rhYOlNk" ) , "ja" , "en" , 1 , true ) ;
// from file
var request = new DubbingRequest ( filePath , "es" , "en" , 1 ) ;
var metadata = await api . DubbingEndpoint . DubAsync ( request , progress : new Progress < DubbingProjectMetadata > ( metadata =>
{
switch ( metadata . Status )
{
case "dubbing" :
Console . WriteLine ( $ "Dubbing for { metadata . DubbingId } in progress... Expected Duration: { metadata . ExpectedDurationSeconds : 0.00 } seconds" ) ;
break ;
case "dubbed" :
Console . WriteLine ( $ "Dubbing for { metadata . DubbingId } complete in { metadata . TimeCompleted . TotalSeconds : 0.00 } seconds!" ) ;
break ;
default :
Console . WriteLine ( $ "Status: { metadata . Status } " ) ;
break ;
}
} ) ) ; まだ進行中かどうかなど、吹き替えプロジェクトについてメタデータを返します。
var api = new ElevenLabsClient ( ) ;
var metadata = api . await GetDubbingProjectMetadataAsync ( "dubbing - id");吹き替えファイルをストリーミングされたファイルとして返します。
注記
ビデオはMP4形式で返され、オーディオのみダブがMP3で返されます。
var assetsDir = Path . GetFullPath ( "../../../Assets" ) ;
var dubbedPath = new FileInfo ( Path . Combine ( assetsDir , $ "online.dubbed. { request . TargetLanguage } .mp4" ) ) ;
{
await using var fs = File . Open ( dubbedPath . FullName , FileMode . Create ) ;
await foreach ( var chunk in ElevenLabsClient . DubbingEndpoint . GetDubbedFileAsync ( metadata . DubbingId , request . TargetLanguage ) )
{
await fs . WriteAsync ( chunk ) ;
}
} 目的の形式でダブのトランスクリプトを返します。
var assetsDir = Path . GetFullPath ( "../../../Assets" ) ;
var transcriptPath = new FileInfo ( Path . Combine ( assetsDir , $ "online.dubbed. { request . TargetLanguage } .srt" ) ) ;
{
var transcriptFile = await api . DubbingEndpoint . GetTranscriptForDubAsync ( metadata . DubbingId , request . TargetLanguage ) ;
await File . WriteAllTextAsync ( transcriptPath . FullName , transcriptFile ) ;
} 吹き替えプロジェクトを削除します。
var api = new ElevenLabsClient ( ) ;
await api . DubbingEndpoint . DeleteDubbingProjectAsync ( "dubbing-id" ) ;テキストをサウンドに変換し、これまでで最も高度なAIオーディオモデルを使用するAPI。
var api = new ElevenLabsClient ( ) ;
var request = new SoundGenerationRequest ( "Star Wars Light Saber parry" ) ;
var clip = await api . SoundGenerationEndpoint . GenerateSoundAsync ( request ) ;メタデータを含む以前に合成されたオーディオクリップへのアクセス。
生成されたすべてのオーディオについてメタデータを入手してください。
var api = new ElevenLabsClient ( ) ;
var historyItems = await api . HistoryEndpoint . GetHistoryAsync ( ) ;
foreach ( var item in historyItems . OrderBy ( historyItem => historyItem . Date ) )
{
Console . WriteLine ( $ " { item . State } { item . Date } | { item . Id } | { item . Text . Length } | { item . Text } " ) ;
} 特定のアイテムに関する情報を取得します。
var api = new ElevenLabsClient ( ) ;
var historyItem = await api . HistoryEndpoint . GetHistoryItemAsync ( voiceClip . Id ) ; var api = new ElevenLabsClient ( ) ;
var voiceClip = await api . HistoryEndpoint . DownloadHistoryAudioAsync ( historyItem ) ;
await File . WriteAllBytesAsync ( $ " { voiceClip . Id } .mp3" , voiceClip . ClipData . ToArray ( ) ) ; 最後の100の歴史アイテム、または指定されたアイテムのコレクションをダウンロードします。
var api = new ElevenLabsClient ( ) ;
var voiceClips = await api . HistoryEndpoint . DownloadHistoryItemsAsync ( ) ; var api = new ElevenLabsClient ( ) ;
var success = await api . HistoryEndpoint . DeleteHistoryItemAsync ( historyItem ) ;
Console . WriteLine ( $ "Was successful? { success } " ) ;ユーザー情報とサブスクリプションステータスへのアクセス。
ユーザーアカウントに関する情報を11枚のenlabsで取得します。
var api = new ElevenLabsClient ( ) ;
var userInfo = await api . UserEndpoint . GetUserInfoAsync ( ) ; サブスクリプションに関する情報を11のenlabsで取得します。
var api = new ElevenLabsClient ( ) ;
var subscriptionInfo = await api . UserEndpoint . GetSubscriptionInfoAsync ( ) ;