# 语音转文本 API

> Use the speech-to-text API to transcribe voice messages.

Vivox 使用以下语音转文本听录方法。

## 启用或禁用听录##enable-or-disable-transcription

### `IVivoxService.SpeechToTextEnableTranscription`##ivivoxservice.speechtotextenabletranscription

```cs
await VivoxService.Instance.SpeechToTextEnableTranscription( _channelName);
```

使用此方法启用频道内的语音转文本听录功能。此方法采用以下参数：

`ChannelName`：要启用听录的频道的名称。

### `IVivoxService.SpeechToTextDisableTranscription`##ivivoxservice.speechtotextdisabletranscription

```cs
await VivoxService.Instance.SpeechToTextDisableTranscription( _channelName);
```

使用此方法禁用频道内的语音转文本听录功能。此方法采用以下参数：

`ChannelName`：要禁用听录的频道的名称。

### `IVivoxService.IsSpeechToTextEnabled`##ivivoxservice.isspeechtotextenabled

```cs
bool isSpeechToTextEnabled = VivoxService.Instance.IsSpeechToTextEnabled(_channelName);
```

使用此方法检查在频道内启用还是禁用了听录。此方法采用以下参数：

`ChannelName`：要检查是否启用了听录的频道的名称。

## 听录通知##transcription-notification

### `IVivoxService.SpeechToTextMessageReceived`##ivivoxservice.speechtotextmessagereceived

```cs
VivoxService.Instance.SpeechToTextMessageReceived += OnSpeechTotextMessageAdded;

VivoxService.Instance.SpeechToTextMessageReceived -= OnSpeechTotextMessageAdded;

private void OnSpeechTotextMessageReceived(VivoxMessage message)
{
    // Add your code here. “message” is the new transcribed message
    // added to the queue.
}
```

将此事件处理程序绑定到某个方法以便在添加听录消息时接收通知，也可取消绑定。

## 设置听录语言##set-transcription-languages

### `LoginOptions.SpeechToTextLanguages`##loginoptions.speechtotextlanguages

```cs
loginOptions = loginOptions ?? new LoginOptions();
loginOptions.SpeechToTextLanguages = new List<string>{"en", "es", "fr"};
```

这是用作音频听录提示的语言列表。默认值为空数组，意味着为 `en`。可以按偏好顺序指定最多三种口头语言，用于告知所有用户在听录频道中的听录。IETF 语言标签字符串未进行验证，但是应符合 [BCP47](https://tools.ietf.org/html/bcp47)(RFC Editor)。
