From 1261b6a5eed062f3571187a8d89ab78b2a5e894e Mon Sep 17 00:00:00 2001 From: allo Date: Tue, 11 Jan 2022 15:41:59 +0800 Subject: translate to zh-CN and convert to markdown --- .../web/api/speechsynthesis/getvoices/index.md | 93 +++++++++------------- 1 file changed, 39 insertions(+), 54 deletions(-) (limited to 'files') diff --git a/files/zh-cn/web/api/speechsynthesis/getvoices/index.md b/files/zh-cn/web/api/speechsynthesis/getvoices/index.md index 5d66a40799..8a46a3f896 100644 --- a/files/zh-cn/web/api/speechsynthesis/getvoices/index.md +++ b/files/zh-cn/web/api/speechsynthesis/getvoices/index.md @@ -1,93 +1,78 @@ --- title: SpeechSynthesis.getVoices() slug: Web/API/SpeechSynthesis/getVoices +tags: + - API + - Method + - Reference + - SpeechSynthesis + - Web Speech API + - getVoices + - speech + - synthesis translation_of: Web/API/SpeechSynthesis/getVoices --- -
{{APIRef("Web Speech API")}}{{SeeCompatTable}}
+{{APIRef("Web Speech API")}} -

The getVoices() method of the {{domxref("SpeechSynthesis")}} interface returns a list of {{domxref("SpeechSynthesisVoice")}} objects representing all the available voices on the current device.

+{{domxref("SpeechSynthesis")}} 接口的 **`getVoices()`** 方法返回一个 {{domxref("SpeechSynthesisVoice")}} 列表,用于表示当前设备上所有可用的语音。 -

Syntax

+## 语法 -
speechSynthesisInstance.getVoices();
-
+```js +getVoices() +``` -

参数

+### 参数 -

None.

+无。 -

返回值

+### 返回值 -

返回一个类型为{{domxref("SpeechSynthesisVoice")}} 的数组(array)列表(list)。

+返回一个类型为 {{domxref("SpeechSynthesisVoice")}} 的数组(array)列表(list)。 -
-

Note: 使用此方法会返回存在错误规范的SpeechSynthesisVoiceList 对象, 可能已被从现有规范中移除。

-
+## 示例 -

示例

+### JavaScript -

JavaScript

- -
function populateVoiceList() {
+```js
+function populateVoiceList() {
   if(typeof speechSynthesis === 'undefined') {
     return;
   }
-
-  voices = speechSynthesis.getVoices();
-
-  for(i = 0; i < voices.length ; i++) {
+  var voices = speechSynthesis.getVoices();
+  for(var i = 0; i < voices.length; i++) {
     var option = document.createElement('option');
     option.textContent = voices[i].name + ' (' + voices[i].lang + ')';
-
     if(voices[i].default) {
       option.textContent += ' -- DEFAULT';
     }
-
     option.setAttribute('data-lang', voices[i].lang);
     option.setAttribute('data-name', voices[i].name);
     document.getElementById("voiceSelect").appendChild(option);
   }
 }
-
 populateVoiceList();
-if (typeof speechSynthesis !== 'undefined' && speechSynthesis.onvoiceschanged !== undefined) {
+if (typeof speechSynthesis !== 'undefined' && speechSynthesis.onvoiceschanged !== undefined) {
   speechSynthesis.onvoiceschanged = populateVoiceList;
-}
- -

HTML

- -
<select id="voiceSelect"></select>
-
+} +``` -

{{EmbedLiveSample("Example", 400, 25)}}

+### HTML -

Specifications

+```html + +``` - - - - - - - - - - - - - -
SpecificationStatusComment
{{SpecName('Web Speech API', '#dfn-ttsgetvoices', 'getVoices()')}}{{Spec2('Web Speech API')}}Initial definition
+{{EmbedLiveSample("示例", 400, 25)}} -

Browser compatibility

+## 规范 -
+{{Specifications}} +## 浏览器兼容性 -

{{Compat("api.SpeechSynthesis.getVoices")}}

-
+{{Compat}} -

See also

+## 参见 - +- [Web Speech API](/zh-CN/docs/Web/API/Web_Speech_API) -- cgit v1.2.3-54-g00ecf