aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorallo <yin199909@aliyun.com>2022-01-11 15:41:59 +0800
committerIrvin <irvinfly@gmail.com>2022-01-19 01:00:39 +0800
commit1261b6a5eed062f3571187a8d89ab78b2a5e894e (patch)
tree3b2f5d52e77e0e30488e87672ec4b706e24e0102
parentd7b986b7ab22dd6a7b31b0761021c018970fd56c (diff)
downloadtranslated-content-1261b6a5eed062f3571187a8d89ab78b2a5e894e.tar.gz
translated-content-1261b6a5eed062f3571187a8d89ab78b2a5e894e.tar.bz2
translated-content-1261b6a5eed062f3571187a8d89ab78b2a5e894e.zip
translate to zh-CN and convert to markdown
-rw-r--r--files/zh-cn/web/api/speechsynthesis/getvoices/index.md93
1 files changed, 39 insertions, 54 deletions
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
---
-<div>{{APIRef("Web Speech API")}}{{SeeCompatTable}}</div>
+{{APIRef("Web Speech API")}}
-<p>The <code><strong>getVoices()</strong></code> method of the {{domxref("SpeechSynthesis")}} interface returns a list of {{domxref("SpeechSynthesisVoice")}} objects representing all the available voices on the current device.</p>
+{{domxref("SpeechSynthesis")}} 接口的 **`getVoices()`** 方法返回一个 {{domxref("SpeechSynthesisVoice")}} 列表,用于表示当前设备上所有可用的语音。
-<h2 id="Syntax">Syntax</h2>
+## 语法
-<pre class="syntaxbox">speechSynthesisInstance.getVoices();
-</pre>
+```js
+getVoices()
+```
-<h3 id="参数">参数</h3>
+### 参数
-<p>None.</p>
+无。
-<h3 id="返回值">返回值</h3>
+### 返回值
-<p>返回一个类型为{{domxref("SpeechSynthesisVoice")}} 的数组(array)列表(list)。</p>
+返回一个类型为 {{domxref("SpeechSynthesisVoice")}} 的数组(array)列表(list)。
-<div class="note">
-<p><strong>Note</strong>: 使用此方法会返回存在错误规范的<code>SpeechSynthesisVoiceList</code> 对象, 可能已被从现有规范中移除。</p>
-</div>
+## 示例
-<h2 id="示例">示例</h2>
+### JavaScript
-<h3 id="JavaScript">JavaScript</h3>
-
-<pre class="brush: js">function populateVoiceList() {
+```js
+function populateVoiceList() {
if(typeof speechSynthesis === 'undefined') {
return;
}
-
- voices = speechSynthesis.getVoices();
-
- for(i = 0; i &lt; 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' &amp;&amp; speechSynthesis.onvoiceschanged !== undefined) {
+if (typeof speechSynthesis !== 'undefined' && speechSynthesis.onvoiceschanged !== undefined) {
speechSynthesis.onvoiceschanged = populateVoiceList;
-}</pre>
-
-<h3 id="HTML">HTML</h3>
-
-<pre class="brush: html">&lt;select id="voiceSelect"&gt;&lt;/select&gt;
-</pre>
+}
+```
-<p>{{EmbedLiveSample("Example", 400, 25)}}</p>
+### HTML
-<h2 id="Specifications">Specifications</h2>
+```html
+<select id="voiceSelect"></select>
+```
-<table class="standard-table">
- <tbody>
- <tr>
- <th scope="col">Specification</th>
- <th scope="col">Status</th>
- <th scope="col">Comment</th>
- </tr>
- <tr>
- <td>{{SpecName('Web Speech API', '#dfn-ttsgetvoices', 'getVoices()')}}</td>
- <td>{{Spec2('Web Speech API')}}</td>
- <td>Initial definition</td>
- </tr>
- </tbody>
-</table>
+{{EmbedLiveSample("示例", 400, 25)}}
-<h2 id="Browser_compatibility">Browser compatibility</h2>
+## 规范
-<div>
+{{Specifications}}
+## 浏览器兼容性
-<p>{{Compat("api.SpeechSynthesis.getVoices")}}</p>
-</div>
+{{Compat}}
-<h2 id="See_also">See also</h2>
+## 参见
-<ul>
- <li><a href="/en-US/docs/Web/API/Web_Speech_API">Web Speech API</a></li>
-</ul>
+- [Web Speech API](/zh-CN/docs/Web/API/Web_Speech_API)