SpeechGrammarList
Deprecated: This feature is no longer recommended. Though some browsers might still support it, it may have already been removed from the relevant web standards, may be in the process of being dropped, or may only be kept for compatibility purposes. Avoid using it, and update existing code if possible; see the compatibility table at the bottom of this page to guide your decision. Be aware that this feature may cease to work at any time.
Giao diện SpeechGrammarList của Web Speech API đại diện cho một danh sách các đối tượng SpeechGrammar chứa các từ hoặc mẫu từ mà chúng ta muốn dịch vụ nhận dạng nhận ra.
Ngữ pháp được định nghĩa bằng cách sử dụng JSpeech Grammar Format (JSGF).
Note: Khái niệm ngữ pháp đã bị loại bỏ khỏi Web Speech API. Các tính năng liên quan vẫn còn trong thông số kỹ thuật và vẫn được các trình duyệt hỗ trợ nhận biết để tương thích ngược, nhưng chúng không có hiệu lực đối với các dịch vụ nhận dạng giọng nói.
Hàm khởi tạo
SpeechGrammarList()Deprecated-
Tạo một đối tượng
SpeechGrammarListmới.
Thuộc tính phiên bản
SpeechGrammarList.lengthRead only Deprecated-
Trả về số lượng đối tượng
SpeechGrammarcó trongSpeechGrammarList.
Phương thức phiên bản
SpeechGrammarList.item()Deprecated-
Getter tiêu chuẩn, cho phép lấy các đối tượng
SpeechGrammarriêng lẻ từSpeechGrammarListbằng cú pháp mảng. SpeechGrammarList.addFromURI()Deprecated-
Lấy một ngữ pháp có tại một URI cụ thể và thêm nó vào
SpeechGrammarListdưới dạng một đối tượngSpeechGrammarmới. SpeechGrammarList.addFromString()Deprecated-
Thêm một ngữ pháp trong một chuỗi vào
SpeechGrammarListdưới dạng một đối tượngSpeechGrammarmới.
Ví dụ
const grammar =
"#JSGF V1.0; grammar colors; public <color> = aqua | azure | beige | bisque | black | blue | brown | chocolate | coral | crimson | cyan | fuchsia | ghostwhite | gold | goldenrod | gray | green | indigo | ivory | khaki | lavender | lime | linen | magenta | maroon | moccasin | navy | olive | orange | orchid | peru | pink | plum | purple | red | salmon | sienna | silver | snow | tan | teal | thistle | tomato | turquoise | violet | white | yellow ;";
const recognition = new SpeechRecognition();
const speechRecognitionList = new SpeechGrammarList();
speechRecognitionList.addFromString(grammar, 1);
recognition.grammars = speechRecognitionList;
Thông số kỹ thuật
| Specification |
|---|
| Web Speech API> # speechgrammarlist> |