SpeechGrammarList: phương thức addFromString()

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.

Phương thức addFromString() của giao diện SpeechGrammarList lấy một ngữ pháp có trong một chuỗi cụ thể trong codebase (ví dụ: được lưu trữ trong một biến) và thêm nó vào SpeechGrammarList dưới dạng một đối tượng SpeechGrammar mới.

Cú pháp

js
addFromString(string)
addFromString(string, weight)

Tham số

string

Một chuỗi đại diện cho ngữ pháp cần thêm.

weight Optional

Một số thực đại diện cho trọng số của ngữ pháp so với các ngữ pháp khác có trong SpeechGrammarList. Trọng số có nghĩa là tầm quan trọng của ngữ pháp này, hoặc khả năng nó được dịch vụ nhận dạng giọng nói nhận ra. Giá trị có thể nằm trong khoảng 0.0 đến 1.0; Nếu không được chỉ định, giá trị mặc định được sử dụng là 1.0.

Giá trị trả về

Không có (undefined).

Thông số kỹ thuật

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

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

Xem thêm