> ## Documentation Index
> Fetch the complete documentation index at: https://devdocs.xbox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# XSpeechSynthesizerEnumerateInstalledVoices

> XSpeechSynthesizerEnumerateInstalledVoices

# XSpeechSynthesizerEnumerateInstalledVoices

インストールされている音声を列挙し、各音声について *callback* が指すメソッドを呼び出します。

## Syntax

```cpp theme={null}
HRESULT XSpeechSynthesizerEnumerateInstalledVoices(  
         void* context,  
         XSpeechSynthesizerInstalledVoicesCallback* callback  
)  
```

### Parameters

*context*   \_In\_opt\_\
型: void\*

呼び出し元固有のデータを回復できるよう、コールバック関数に渡されるユーザー指定の変数。

*callback*   \_In\_\
型: [XSpeechSynthesizerInstalledVoicesCallback](/reference/system/xspeechsynthesizer/functions/xspeechsynthesizerinstalledvoicescallback)\*

インストールされている各音声に対して 1 回呼び出されるメソッドへのポインター。

### Return value

型: [HRESULT](https://learn.microsoft.com/openspecs/windows_protocols/ms-erref/0642cb2f-2075-4469-918c-4441e69c548a)

成功した場合は **S\_OK** を返します。そうでない場合はエラー コードを返します。エラー コードの一覧については、[エラー コード](/reference/errorcodes) を参照してください。

## Remarks

<Note>この関数はタイム センシティブ スレッドで呼び出すのは安全ではありません。詳細については、[タイム センシティブ スレッド](https://learn.microsoft.com/gaming/gdk/docs/gdk-dev/console-dev/overviews/threads/time-sensitive-threads) を参照してください。</Note>

この関数は、デバイスにインストールされている音声合成エンジン (*音声*) を列挙します。この関数は、*callback* で指定された [XSpeechSynthesizerInstalledVoicesCallback](/reference/system/xspeechsynthesizer/functions/xspeechsynthesizerinstalledvoicescallback) コールバック関数を、インストールされている音声ごとに 1 回呼び出し、その音声に関する情報を含む [XSpeechSynthesizerVoiceInformation](/reference/system/xspeechsynthesizer/structs/xspeechsynthesizervoiceinformation) 構造体を渡します。

次の例は、**XSpeechSynthesizerEnumerateInstalledVoices** 関数を呼び出して、デバイス上にインストールされている音声を列挙する方法を示しています。この例は、**XSpeechSynthesizerInstalledVoicesCallback** コールバック関数を呼び出して、(1) デバイスにインストールされている音声の数を数え、(2) **XSpeechSynthesizerVoiceInformation** 構造体から、インストールされている各音声に関する情報をデバッガーに出力します。

```cpp theme={null}
int Game::CountInstalledVoices()
{
    HRESULT hr = S_OK;
    int* voiceCount = new int();
    // Call XSpeechSynthesizerEnumerateInstalledVoices with a callback function
    // defined as a lambda expression that increments the count of installed voices 
    // each time it's invoked, and outputs information about each voice to the 
    // debugger for display.
    hr = XSpeechSynthesizerEnumerateInstalledVoices(voiceCount,
        [](
            _In_ const XSpeechSynthesizerVoiceInformation* information,
            _In_ void* context
            ) -> bool 
        {
        // Increment and update the count of installed voices.
        int* voiceCount = (int*)context;
        *voiceCount = *voiceCount + 1;
        CopyMemory(context, voiceCount, sizeof(int));

        // Output information about the current installed voice
        // to the debugger for display.
        char buffer[1000];
        int bufferLen;
        bufferLen = sprintf(buffer, "(%s) %s - %s, %s\n",
            information->VoiceId,
            information->Description,
            information->Gender == XSpeechSynthesizerVoiceGender::Male ? "Male" : "Female",
            information->Language);
        OutputDebugStringA(buffer);
      
        // Continue iterating through installed voices.
        // If this was set to false, the calling function would stop
        // enumerating installed voices.
        return true;
        }
    );

    // Return the count of installed voices.
    return *voiceCount;
}
```

## Requirements

**ヘッダー:** XSpeechSynthesizer.h

**ライブラリ:** xgameruntime.lib

**サポートされているプラットフォーム:** Windows、XBOX One ファミリー本体および XBOX Series 本体

## Conceptual documentation

* [タイム センシティブ スレッド](https://learn.microsoft.com/gaming/gdk/docs/gdk-dev/console-dev/overviews/threads/time-sensitive-threads)

## See also

[XAccessibility](/reference/system/xaccessibility/xaccessibility_members)\
[XSpeechSynthesizerSetCustomVoice](/reference/system/xspeechsynthesizer/functions/xspeechsynthesizersetcustomvoice)\
[XSpeechSynthesizer](/reference/system/xspeechsynthesizer/xspeechsynthesizer_members)


## Related topics

- [XSpeechSynthesizerInstalledVoicesCallback](/ja-jp/reference/system/xspeechsynthesizer/functions/xspeechsynthesizerinstalledvoicescallback.md)
- [XSpeechSynthesizerVoiceGender](/ja-jp/reference/system/xspeechsynthesizer/enums/xspeechsynthesizervoicegender.md)
- [XSpeechSynthesizerVoiceInformation](/ja-jp/reference/system/xspeechsynthesizer/structs/xspeechsynthesizervoiceinformation.md)
- [XSpeechSynthesizer](/ja-jp/reference/system/xspeechsynthesizer/xspeechsynthesizer_members.md)
- [XSpeechSynthesizerSetDefaultVoice](/ja-jp/reference/system/xspeechsynthesizer/functions/xspeechsynthesizersetdefaultvoice.md)
