Html Chrome 实现的 HTML5 语音识别 API 中的语言代码是什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14257598/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 04:53:14  来源:igfitidea点击:

What are language codes in Chrome's implementation of the HTML5 speech recognition API?

htmlgoogle-chromespeech-recognitionvoicevoice-recognition

提问by weilou

Chrome implemented the HTML5 speech recognition API. Many languages are supported. I wanna know which languages are supported and each language's corresponding code which is used in the HTML element's langattribute.

Chrome 实现了 HTML5 语音识别 API。支持多种语言。我想知道支持哪些语言以及在 HTML 元素的lang属性中使用的每种语言的相应代码。

For instance:

例如:

  • Polish (pl-PL)
  • Turkish (tr-TR)
  • 波兰语 (pl-PL)
  • 土耳其语 (tr-TR)

Thank you!

谢谢!

回答by Sergey Zyuzin

Ok, if it is not published, we can try to at least figure this out. Let me put this table for the beginning and we will refine it if someone has more information.

好吧,如果它没有发布,我们至少可以尝试解决这个问题。让我把这张表放在开头,如果有人有更多信息,我们会完善它。

I'm making assumption that supported languages shall be similar to those supported by voice search and that google uses standard language codes and does that consistently across its services.

我假设支持的语言应类似于语音搜索支持的语言,并且谷歌使用标准语言代码并在其服务中一致地这样做。

I've looked up languages supported by voice search on wikipedia

我在维基百科上查找了语音搜索支持的语言

I've found language codes here, on google language settings pageand here

我在这里谷歌语言设置页面这里找到了语言代码

EDIT:I've experimented with backend voice recognition service. I've run a series of tests where I've passed the same english speech sample to the API but specified different dialect every time. It looks like:

编辑:我已经尝试过后端语音识别服务。我运行了一系列测试,其中我将相同的英语语音样本传递给 API,但每次都指定不同的方言。看起来像:

  • If a language is not supported, recognition falls back to en-US (looks like it recognizes that the sample is in english)
  • If a dialect is not supported (or doesn't exist) recognition falls back to main dialect or en-US in some cases
  • Main dialect can be specified just as first part of identifier. So 'en-US' and 'en' gives same results.
  • Recognition for some languages, like chinese and japanese gives results in english, different from en-US though, which is strange. Probably the sample is different very much from chinese and the service is clever to figure that out.
  • 如果不支持某种语言,则识别回退到 en-US(看起来它识别出样本是英文的)
  • 如果方言不受支持(或不存在),则在某些情况下,识别会回退到主要方言或 en-US
  • 可以将主要方言指定为标识符的第一部分。所以 'en-US' 和 'en' 给出相同的结果。
  • 识别某些语言,如中文和日语,结果是英语,但与 en-US 不同,这很奇怪。可能样本与china有很大不同,服务很聪明地解决了这一点。

I treat a dialect as supported if recognition gives a different result from en-US and from main dialect for the language. Still, to verify it 100% we need to run samples for each language.

如果识别结果与 en-US 和该语言的主要方言不同,我会将方言视为受支持的方言。尽管如此,为了 100% 验证它,我们需要为每种语言运行样本。

Legend

传奇

  • +Most of all supported, because test gives a result different from en-US and main dialect.
  • .+Absent on wikipedia but most of all supported, because test gives result different from en-US and main dialect.
  • +?Most of all supported because it is listed on wikipedia. But test on my sample gives result identical to the main dialect. So either this is a coinsidense or language code is wrong.
  • .+?Not listed on wikipedia but looks like supported, because test gives result different from en-US and main dialect.
  • +最重要的是支持,因为测试给出的结果不同于 en-US 和主要方言。
  • .+维基百科上没有,但最重要的是支持,因为测试给出的结果与美国和主要方言不同。
  • +?最重要的是支持,因为它列在维基百科上。但是对我的样本进行测试得出的结果与主要方言相同。所以这是一个coinsideense或语言代码是错误的。
  • .+?维基百科上未列出但看起来受支持,因为测试给出的结果与 en-US 和主要方言不同。

Languages

语言

  • +Afrikaans af
  • +Basque eu
  • +Bulgarian bg
  • +Catalan ca
  • +Arabic (Egypt) ar-EG
  • +?Arabic (Jordan) ar-JO
  • +Arabic (Kuwait) ar-KW
  • +?Arabic (Lebanon) ar-LB
  • +Arabic (Qatar) ar-QA
  • +Arabic (UAE) ar-AE
  • .+Arabic (Morocco) ar-MA
  • .+Arabic (Iraq) ar-IQ
  • .+Arabic (Algeria) ar-DZ
  • .+Arabic (Bahrain) ar-BH
  • .+Arabic (Lybia) ar-LY
  • .+Arabic (Oman) ar-OM
  • .+Arabic (Saudi Arabia) ar-SA
  • .+Arabic (Tunisia) ar-TN
  • .+Arabic (Yemen) ar-YE
  • +Czech cs
  • +Dutch nl-NL
  • +English (Australia) en-AU
  • +?English (Canada) en-CA
  • +English (India) en-IN
  • +English (New Zealand) en-NZ
  • +English (South Africa) en-ZA
  • +English(UK) en-GB
  • +English(US) en-US
  • +Finnish fi
  • +French fr-FR
  • +Galician gl
  • +German de-DE
  • +Hebrew he
  • +Hungarian hu
  • +Icelandic is
  • +Italian it-IT
  • +Indonesian id
  • +Japanese ja
  • +Korean ko
  • +Latin la
  • +Mandarin Chinese zh-CN
  • +Traditional Taiwan zh-TW
  • +?Simplified China zh-CN?
  • +Simplified Hong Kong zh-HK
  • +Yue Chinese (Traditional Hong Kong) zh-yue
  • +Malaysian ms-MY
  • +Norwegian no-NO
  • +Polish pl
  • +?Pig Latin xx-piglatin
  • +Portuguese pt-PT
  • .+Portuguese (brasil) pt-BR
  • +Romanian ro-RO
  • +Russian ru
  • +Serbian sr-SP
  • +Slovak sk
  • +Spanish (Argentina) es-AR
  • +Spanish(Bolivia) es-BO
  • +?Spanish( Chile) es-CL
  • +?Spanish (Colombia) es-CO
  • +?Spanish(Costa Rica) es-CR
  • +Spanish(Dominican Republic) es-DO
  • +Spanish(Ecuador) es-EC
  • +Spanish(El Salvador) es-SV
  • +Spanish(Guatemala) es-GT
  • +Spanish(Honduras) es-HN
  • +Spanish(Mexico) es-MX
  • +Spanish(Nicaragua) es-NI
  • +Spanish(Panama) es-PA
  • +Spanish(Paraguay) es-PY
  • +Spanish(Peru) es-PE
  • +Spanish(Puerto Rico) es-PR
  • +Spanish(Spain) es-ES
  • +Spanish(US) es-US
  • +Spanish(Uruguay) es-UY
  • +Spanish(Venezuela) es-VE
  • +Swedish sv-SE
  • +Turkish tr
  • +Zulu zu
  • +南非 AF
  • +巴斯克语
  • +保加利亚语 bg
  • +加泰罗尼亚 CA
  • +阿拉伯语(埃及) ar-EG
  • +?阿拉伯语(约旦)ar-JO
  • +阿拉伯语(科威特) ar-KW
  • +?阿拉伯语(黎巴嫩) ar-LB
  • +阿拉伯语(卡塔尔) ar-QA
  • +阿拉伯语 (UAE) ar-AE
  • .+阿拉伯语(摩洛哥)ar-MA
  • .+阿拉伯语(伊拉克)ar-IQ
  • .+阿拉伯语(阿尔及利亚)ar-DZ
  • .+阿拉伯语(巴林)ar-BH
  • .+阿拉伯语(利比亚)ar-LY
  • .+阿拉伯语(阿曼)ar-OM
  • .+阿拉伯语(沙特阿拉伯)ar-SA
  • .+阿拉伯语(突尼斯)ar-TN
  • .+Arabic (Yemen) ar-YE
  • +捷克语 cs
  • +荷兰语 nl-NL
  • +英语(澳大利亚) en-AU
  • +?英语(加拿大) en-CA
  • +英语(印度) en-IN
  • +英语(新西兰) en-NZ
  • +英语(南非) en-ZA
  • +英语(英国) en-GB
  • +英语(美国) en-US
  • +芬兰 网络
  • +法语 fr-FR
  • +加利西亚GL
  • +German de-DE
  • +希伯来语 he
  • +匈牙利
  • +冰岛语
  • +意大利语 IT
  • +印尼
  • +日语
  • +我是韩国人
  • +拉丁语 la
  • +普通话 zh-CN
  • +传统台湾 zh-TW
  • +?简体中文 zh-CN?
  • +简体香港zh-HK
  • +Yue Chinese (Traditional Hong Kong) zh-yue
  • +马来西亚 ms-MY
  • +挪威语 no-NO
  • +波兰语 pl
  • +?猪拉丁语 xx-piglatin
  • +葡萄牙语 pt-PT
  • .+葡萄牙语(巴西) pt-BR
  • +罗马尼亚 滚装
  • +Russian ru
  • +塞尔维亚语 sr-SP
  • +斯洛伐克 sk
  • +西班牙语(阿根廷) es-AR
  • +西班牙语(玻利维亚) es-BO
  • +?西班牙语(智利) es-CL
  • +?西班牙语(哥伦比亚) es-CO
  • +?西班牙语(哥斯达黎加) es-CR
  • +西班牙语(多米尼加共和国) es-DO
  • +西班牙语(厄瓜多尔) es-EC
  • +西班牙语(萨尔瓦多)es-SV
  • +西班牙语(危地马拉) es-GT
  • +西班牙语(洪都拉斯) es-HN
  • +西班牙语(墨西哥) es-MX
  • +西班牙语(尼加拉瓜) en-NI
  • +西班牙语(巴拿马) es-PA
  • +西班牙语(巴拉圭) es-PY
  • +西班牙语(秘鲁) es-PE
  • +西班牙语(波多黎各)es-PR
  • +西班牙语(西班牙) es-ES
  • +西班牙语(美国) es-US
  • +西班牙语(乌拉圭) es-UY
  • +西班牙语(委内瑞拉) es-VE
  • +瑞典语 sv-SE
  • +土耳其 TR
  • +Zulu zu

回答by TimHayes

I know this is an old post, but since this information is annoyingly hard to find I thought I'd post a list for anyone who might be looking. Please leave a note if you find any errors or omissions.

我知道这是一个旧帖子,但由于这些信息很难找到,我想我会为可能正在寻找的任何人发布一个列表。如果您发现任何错误或遗漏,请留言。

{
  "Afrikaans": [
    ["South Africa", "af-ZA"]
  ],
  "Arabic" : [
    ["Algeria","ar-DZ"],
    ["Bahrain","ar-BH"],
    ["Egypt","ar-EG"],
    ["Israel","ar-IL"],
    ["Iraq","ar-IQ"],
    ["Jordan","ar-JO"],
    ["Kuwait","ar-KW"],
    ["Lebanon","ar-LB"],
    ["Morocco","ar-MA"],
    ["Oman","ar-OM"],
    ["Palestinian Territory","ar-PS"],
    ["Qatar","ar-QA"],
    ["Saudi Arabia","ar-SA"],
    ["Tunisia","ar-TN"],
    ["UAE","ar-AE"]
  ],
  "Basque": [
    ["Spain", "eu-ES"]
  ],
  "Bulgarian": [
    ["Bulgaria", "bg-BG"]
  ],
  "Catalan": [
    ["Spain", "ca-ES"]
  ],
  "Chinese Mandarin": [
    ["China (Simp.)", "cmn-Hans-CN"],
    ["Hong Kong SAR (Trad.)", "cmn-Hans-HK"],
    ["Taiwan (Trad.)", "cmn-Hant-TW"]
  ],
  "Chinese Cantonese": [
    ["Hong Kong", "yue-Hant-HK"]
  ],
  "Croatian": [
    ["Croatia", "hr_HR"]
  ],
  "Czech": [
    ["Czech Republic", "cs-CZ"]
  ],
  "Danish": [
    ["Denmark", "da-DK"]
  ],
  "English": [
    ["Australia", "en-AU"],
    ["Canada", "en-CA"],
    ["India", "en-IN"],
    ["Ireland", "en-IE"],
    ["New Zealand", "en-NZ"],
    ["Philippines", "en-PH"],
    ["South Africa", "en-ZA"],
    ["United Kingdom", "en-GB"],
    ["United States", "en-US"]
  ],
  "Farsi": [
    ["Iran", "fa-IR"]
  ],
  "French": [
    ["France", "fr-FR"]
  ],
  "Filipino": [
    ["Philippines", "fil-PH"]
  ],
  "Galician": [
    ["Spain", "gl-ES"]
  ],
  "German": [
    ["Germany", "de-DE"]
  ],
  "Greek": [
    ["Greece", "el-GR"]
  ],
  "Finnish": [
    ["Finland", "fi-FI"]
  ],
  "Hebrew" :[
    ["Israel", "he-IL"]
  ],
  "Hindi": [
    ["India", "hi-IN"]
  ],
  "Hungarian": [
    ["Hungary", "hu-HU"]
  ],
  "Indonesian": [
    ["Indonesia", "id-ID"]
  ],
  "Icelandic": [
    ["Iceland", "is-IS"]
  ],
  "Italian": [
    ["Italy", "it-IT"],
    ["Switzerland", "it-CH"]
  ],
  "Japanese": [
    ["Japan", "ja-JP"]
  ],
  "Korean": [
    ["Korea", "ko-KR"]
  ],
  "Lithuanian": [
    ["Lithuania", "lt-LT"]
  ],
  "Malaysian": [
    ["Malaysia", "ms-MY"]
  ],
  "Dutch": [
    ["Netherlands", "nl-NL"]
  ],
  "Norwegian": [
    ["Norway", "nb-NO"]
  ],
  "Polish": [
    ["Poland", "pl-PL"]
  ],
  "Portuguese": [
    ["Brazil", "pt-BR"],
    ["Portugal", "pt-PT"]
  ],
  "Romanian": [
    ["Romania", "ro-RO"]
  ],
  "Russian": [
    ["Russia", "ru-RU"]
  ],
  "Serbian": [
    ["Serbia", "sr-RS"]
  ],
  "Slovak": [
    ["Slovakia", "sk-SK"]
  ],
  "Slovenian": [
    ["Slovenia", "sl-SI"]
  ],
  "Spanish": [
    ["Argentina", "es-AR"],
    ["Bolivia", "es-BO"],
    ["Chile", "es-CL"],
    ["Colombia", "es-CO"],
    ["Costa Rica", "es-CR"],
    ["Dominican Republic", "es-DO"],
    ["Ecuador", "es-EC"],
    ["El Salvador", "es-SV"],
    ["Guatemala", "es-GT"],
    ["Honduras", "es-HN"],
    ["México", "es-MX"],
    ["Nicaragua", "es-NI"],
    ["Panamá", "es-PA"],
    ["Paraguay", "es-PY"],
    ["Perú", "es-PE"],
    ["Puerto Rico", "es-PR"],
    ["Spain", "es-ES"],
    ["Uruguay", "es-UY"],
    ["United States", "es-US"],
    ["Venezuela", "es-VE"]
  ],
  "Swedish": [
    ["Sweden", "sv-SE"]
  ],
  "Thai": [
    ["Thailand", "th-TH"]
  ],
  "Turkish": [
    ["Turkey", "tr-TR"]
  ],
  "Ukrainian": [
    ["Ukraine", "uk-UA"]
  ],
  "Vietnamese": [
    ["Viet Nam", "vi-VN"]
  ],
  "Zulu": [
    ["South Africa", "zu-ZA"]
  ]
}

Edit: I also found this list, which is probably more current: https://cloud.google.com/speech-to-text/docs/languages

编辑:我还找到了这个列表,它可能是最新的:https: //cloud.google.com/speech-to-text/docs/languages

回答by mesosteros

Use the following code to get all available voices for the speech API in your browser:

使用以下代码在浏览器中获取语音 API 的所有可用语音:

var voices = speechSynthesis.getVoices();
      for(var i = 0; i < voices.length; i++ ) {
        console.log("Voice " + i.toString() + ' ' + voices[i].name + ' ' + voices[i].uri);
      }

At this time only Chrome and Safari support the Web Speech API (although Safari only supports the Text to Speech functionalities). Curiously Firefox OS supports TTS but the browser version does not.

目前只有 Chrome 和 Safari 支持 Web Speech API(虽然 Safari 只支持 Text to Speech 功能)。奇怪的是 Firefox OS 支持 TTS,但浏览器版本不支持。

The list of languages depends on what browser you are on according to both the documentation and my tests (user agent dependent).

根据文档和我的测试(依赖于用户代理),语言列表取决于您使用的浏览器。

In Safari you also get lots of languages available (I believe over 40). In Chrome, at this time you get the following list:

在 Safari 中,您还可以使用多种语言(我相信超过 40 种)。在 Chrome 中,此时您会得到以下列表:

Voice 0 Google US English undefined

语音 0 谷歌美国英语 undefined

Voice 1 Google UK English Male undefined

Voice 1 Google UK English 男 undefined

Voice 2 Google UK English Female undefined

Voice 2 Google UK English 女性 undefined

Voice 3 Google Espa?ol undefined

Voice 3 Google Espa?ol undefined

Voice 4 Google Fran?ais undefined

Voice 4 Google Fran?ais undefined

Voice 5 Google Italiano undefined

Voice 5 Google Italiano undefined

Voice 6 Google Deutsch undefined

Voice 6 Google Deutsch undefined

Voice 7 Google 日本人 undefined

Voice 7 Google 日本人 undefined

Voice 8 Google ??? undefined

语音 8 谷歌???不明确的

Voice 9 Google china的 undefined

Voice 9 Google china的 undefined

Voice 10 native undefined

Voice 10 原生 undefined

回答by Waffles.Inc

Here you have @TimHayes in a LinkedHashMap where you can fetch the values. Im using LinkedHashMap so I can get the position of the map.

在这里,您在 LinkedHashMap 中有 @TimHayes,您可以在其中获取值。我使用 LinkedHashMap 所以我可以得到地图的位置。

    LinkedHashMap<String,String> country = new LinkedHashMap<String,String>();


    country.put("South Africa", "af-ZA");
    country.put("Algeria", "ar-DZ");
    country.put("Bahrain", "ar-BH");
    country.put("Egypt", "ar-EG");
    country.put("Israel", "ar-IL");
    country.put("Iraq", "ar-IQ");
    country.put("Jordan", "ar-JO");
    country.put("Kuwait", "ar-KW");
    country.put("Lebanon", "ar-LB");
    country.put("Morocco", "ar-MA");
    country.put("Oman", "ar-OM");
    country.put("Palestinian Territory", "ar-PS");
    country.put("Qatar", "ar-QA");
    country.put("Saudi Arabia", "ar-SA");
    country.put("Tunisia", "ar-TN");
    country.put("UAE", "ar-AE");
    country.put("Spain", "eu-ES");
    country.put("Bulgaria", "bg-BG");
    country.put("Spain", "ca-ES");
    country.put("China (Simp.)", "cmn-Hans-CN");
    country.put("Hong Kong SAR (Trad.)", "cmn-Hans-HK");
    country.put("Taiwan (Trad.)", "cmn-Hant-TW");
    country.put("Hong Kong", "yue-Hant-HK");
    country.put("Croatia", "hr_HR");
    country.put("Czech Republic", "cs-CZ");
    country.put("Denmark", "da-DK");
    country.put("Australia", "en-AU");
    country.put("Canada", "en-CA");
    country.put("India", "en-IN");
    country.put("Ireland", "en-IE");
    country.put("New Zealand", "en-NZ");
    country.put("Philippines", "en-PH");
    country.put("South Africa", "en-ZA");
    country.put("United Kingdom", "en-GB");
    country.put("United States", "en-US");
    country.put("Iran", "fa-IR");
    country.put("France", "fr-FR");
    country.put("Philippines", "fil-PH");
    country.put("Spain", "gl-ES");
    country.put("Germany", "de-DE");
    country.put("Greece", "el-GR");
    country.put("Finland", "fi-FI");
    country.put("Israel", "he-IL");
    country.put("India", "hi-IN");
    country.put("Hungary", "hu-HU");
    country.put("Indonesia", "id-ID");
    country.put("Iceland", "is-IS");
    country.put("Italy", "it-IT");
    country.put("Switzerland", "it-CH");
    country.put("Japan", "ja-JP");
    country.put("Korea", "ko-KR");
    country.put("Lithuania", "lt-LT");
    country.put("Malaysia", "ms-MY");
    country.put("Netherlands", "nl-NL");
    country.put("Norway", "nb-NO");
    country.put("Poland", "pl-PL");
    country.put("Brazil", "pt-BR");
    country.put("Portugal", "pt-PT");
    country.put("Romania", "ro-RO");
    country.put("Russia", "ru-RU");
    country.put("Serbia", "sr-RS");
    country.put("Slovakia", "sk-SK");
    country.put("Slovenia", "sl-SI");
    country.put("Argentina", "es-AR");
    country.put("Bolivia", "es-BO");
    country.put("Chile", "es-CL");
    country.put("Colombia", "es-CO");
    country.put("Costa Rica", "es-CR");
    country.put("Dominican Republic", "es-DO");
    country.put("Ecuador", "es-EC");
    country.put("El Salvador", "es-SV");
    country.put("Guatemala", "es-GT");
    country.put("Honduras", "es-HN");
    country.put("México", "es-MX");
    country.put("Nicaragua", "es-NI");
    country.put("Panamá", "es-PA");
    country.put("Paraguay", "es-PY");
    country.put("Perú", "es-PE");
    country.put("Puerto Rico", "es-PR");
    country.put("Spain", "es-ES");
    country.put("Uruguay", "es-UY");
    country.put("United States", "es-US");
    country.put("Venezuela", "es-VE");
    country.put("Sweden", "sv-SE");
    country.put("Thailand", "th-TH");
    country.put("Turkey", "tr-TR");
    country.put("Ukraine", "uk-UA");
    country.put("Viet Nam", "vi-VN");
    country.put("South Africa", "zu-ZA");