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

Limited availability

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 SpeechRecognitionResult là một getter tiêu chuẩn cho phép truy cập các đối tượng SpeechRecognitionAlternative trong kết quả thông qua cú pháp mảng.

Cú pháp

js
item(index)

Tham số

index

Chỉ mục của mục cần truy xuất.

Giá trị trả về

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

Ví dụ

Đoạn mã 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 = `Result received: ${color}.`;
  bg.style.backgroundColor = color;
};

Thông số kỹ thuật

Specification
Web Speech API
# dom-speechrecognitionresult-item

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

Xem thêm