SpeechRecognitionResultList: phương thức item()

Khả dụng hạn chế

This feature is not Baseline because it does not work in some of the most widely-used browsers.

Getter item của giao diện SpeechRecognitionResultList là một getter tiêu chuẩn — nó cho phép truy cập các đối tượng SpeechRecognitionResult trong danh sách qua cú pháp mảng.

Cú pháp

js
item(index)

Tham số

index

Chỉ mục của item cần lấy.

Giá trị trả về

Một đối tượng SpeechRecognitionResult.

Ví dụ

Code này được trích từ ví dụ Speech color changer của chúng tôi.

js
recognition.onresult = (event) => {
  const color = event.results[0][0].transcript;
  diagnostic.textContent = `Nhận được kết quả: ${color}.`;
  bg.style.backgroundColor = color;
};

Thông số kỹ thuật

Thông số kỹ thuật
Web Speech API
# dom-speechrecognitionresultlist-item

Tương thích trình duyệt

Xem thêm