Custom Speech で作成したモデルを Speech Translation で使用する方法

  1. 1. Custom Speech で作成したモデルを Speech Translation で使用する方法
    1. 1.1. C# (.NET) を使用する場合のコード例:
    2. 1.2. JavaScript を使用する場合のコード例:
      1. 1.2.1. 補足
    3. 1.3. 翻訳のカスタマイズについて

Custom Speech で作成したモデルを Speech Translation で使用する方法をご紹介します。



Custom Speech で作成したモデルを Speech Translation で使用する方法

Speech Services の音声翻訳 (Speech Translation) は、まず Speech-to-Text で文字起こしされた結果を元に Text Translation で翻訳を行います。

この時、Speech-to-Text の処理で使用される音声認識モデルは Custom Speech でカスタマイズすることができます。

C# (.NET) を使用する場合のコード例:

SpeechTranslationConfig のプロパティ EndpointId にモデルのエンドポイント ID を指定します。

1
2
3
4
5
6
7
8
SpeechTranslationConfig config = SpeechTranslationConfig.FromSubscription(SubscriptionKey, Region);

// Custom Speech のモデル指定
// 例: エンドポイント ID が 51747863-4b1a-4efa-a1cb-84be48ae50d7 の場合

config.EndpointId = "51747863-4b1a-4efa-a1cb-84be48ae50d7";

// 以降の音声認識・翻訳は通常と同じ

JavaScript を使用する場合のコード例:

Speech SDK for JavaScript の場合、Speech to Text では endpointId を使用していますが、Speech Translation では endpointId のプロパティは参照されません。
そのため、エンドポイントの URL パラメーター cid として指定する必要があります。

1
2
3
4
5
// リージョンが Japan East, エンドポイント ID が 51747863-4b1a-4efa-a1cb-84be48ae50d7 の場合

speechConfig = SpeechSDK.SpeechTranslationConfig.fromEndpoint(new URL("wss://japaneast.s2s.speech.microsoft.com/speech/translation/cognitiveservices/v1?cid=51747863-4b1a-4efa-a1cb-84be48ae50d7"),settings.subscriptionKey);

// 以降の音声認識・翻訳は通常と同じ

エンドポイントの URL を確認する方法については、こちらのドキュメントの “エンドポイント URL の構築” をご参照ください。

補足

Speech Translation の場合に endpointId が参照されないことは GitHub で公開されているソースコードからご確認いただけます。

Speech to Text の場合:

TranscriberConnectionFactory.ts より抜粋:

1
2
3
public setQueryParams(queryParams: IStringDictionary<string>, config: RecognizerConfig, endpointUrl: string): void {

const endpointId: string = config.parameters.getProperty(PropertyId.SpeechServiceConnection_EndpointId, undefined);

Speech Translation の場合:

TranslationConnectionFactory.ts より抜粋:

1
2
3
4
5
6
public setQueryParams(queryParams: IStringDictionary<string>, config: RecognizerConfig, endpointUrl: string): void {
// Common parameters for both V1 and V2 endpoints
queryParams.from = config.parameters.getProperty(PropertyId.SpeechServiceConnection_RecoLanguage);
queryParams.to = config.parameters.getProperty(PropertyId.SpeechServiceConnection_TranslationToLanguages);
queryParams.scenario = config.recognitionMode === RecognitionMode.Interactive ? "interactive" :
config.recognitionMode === RecognitionMode.Conversation ? "conversation" : "";

翻訳のカスタマイズについて

Custom Translator で作成した翻訳モデルも同時に使用する場合はこちらのブログをご参照ください。


変更履歴
2025/05/02 created by Nakagami