SpeechRecognitionResult: свойство length
Ограниченная доступность
Эта функция не является базовой, так как она не работает во всех широко используемых браузерах.
Чтение-только свойство length интерфейса SpeechRecognitionResult возвращает длину «массива» — количество объектов SpeechRecognitionAlternative, содержащихся в результате (также называемых «n-лучшими альтернативами»).
Количество альтернатив в результате зависит от значения свойства SpeechRecognition.maxAlternatives, установленного при первом запуске распознавания речи.
Значение
Число.
Примеры
Этот код взят из нашего примера Смена цвета речи.
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[0].length);
};
Спецификации
| Спецификация |
|---|
| Web Speech API # dom-speechrecognitionresult-length |
Совместимость с браузерами
| Рабочий стол | Мобильные устройства | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari на IOS | Samsung Internet | WebView Android | |
length |
33 | 79 | Нет | Нет | 14.1 | 33 | Нет | Нет | 14.5 | 2.0 | 4.4.3 |
См. также
© 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/SpeechRecognitionResult/length