SpeechGrammar
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 SpeechGrammar của Web Speech API đại diện cho một tập hợp các từ hoặc các mẫu từ để dịch vụ nhận dạng nhận biết.
Ngữ pháp được định nghĩa sử dụng JSpeech Grammar Format (JSGF).
Note: Khái niệm ngữ pháp đã bị xóa 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ợ để tương thích ngược, nhưng chúng không có tác dụng đối với dịch vụ nhận dạng giọng nói.
Hàm khởi tạo
SpeechGrammar()Không chuẩn Đã lỗi thời-
Tạo đối tượng
SpeechGrammarmới.
Thuộc tính phiên bản
SpeechGrammar.srcĐã lỗi thời-
Đặt và trả về chuỗi chứa ngữ pháp từ bên trong phiên bản đối tượng
SpeechGrammar. SpeechGrammar.weightOptional Đã lỗi thời-
Đặt và trả về trọng số của đối tượng
SpeechGrammar.
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;
console.log(speechRecognitionList[0].src); // nên trả về cùng nội dung như biến grammar
console.log(speechRecognitionList[0].weight); // nên trả về 1 - giống trọng số được đặt trong addFromString.
Thông số kỹ thuật
| Thông số kỹ thuật |
|---|
| Web Speech API> # speechreco-speechgrammar> |