Spec-Zone.ru › Web APIs

SpeechRecognitionResultList: свойство length

Ограниченная доступность

Эта функция не относится к Baseline, так как она не работает во всех широко используемых браузерах.

  • Подробнее
  • Полная совместимость
  • Отправить отзыв

Чтение-только свойство length интерфейса SpeechRecognitionResultList возвращает длину «массива» — количество объектов SpeechRecognitionResult в списке.

Значение

Число.

Примеры

Этот код взят из нашего примера Изменение цвета речи.

recognition.onresult = (event) => {
  // The SpeechRecognitionEvent results property returns a SpeechRecognitionResultList object
  // The SpeechRecognitionResultList object contains SpeechRecognitionResult objects.
  // It has a getter so it can be accessed like an array
  // The first [0] returns the SpeechRecognitionResult at position 0.
  // Each SpeechRecognitionResult object contains SpeechRecognitionAlternative objects
  // that contain individual results.
  // These also have getters so they can be accessed like arrays.
  // The second [0] returns the SpeechRecognitionAlternative at position 0.
  // We then return the transcript property of the SpeechRecognitionAlternative object
  const color = event.results[0][0].transcript;
  diagnostic.textContent = `Result received: ${color}.`;
  bg.style.backgroundColor = color;

  console.log(event.results.length);
};

Спецификации

Спецификация
Web Speech API
# dom-speechrecognitionresultlist-length

Совместимость браузеров

Рабочий стол Мобильные устройства
Chrome Edge Firefox Opera Safari Chrome Android Firefox для Android Opera Android Safari на iOS Samsung Internet WebView Android
length 33 79 Нет Нет 14.1 33 Нет Нет 14.5 2.0 4.4.3

См. также

  • Web Speech API

© 2005–2024 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/SpeechRecognitionResultList/length

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API