This repository has been archived by the owner on Sep 11, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 732
Update speech-color-changer to be compatible with Safari #64
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,18 @@ | ||
var SpeechRecognition = SpeechRecognition || webkitSpeechRecognition | ||
var SpeechGrammarList = SpeechGrammarList || webkitSpeechGrammarList | ||
var SpeechGrammarList = SpeechGrammarList || window.webkitSpeechGrammarList | ||
var SpeechRecognitionEvent = SpeechRecognitionEvent || webkitSpeechRecognitionEvent | ||
|
||
var colors = [ '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']; | ||
var grammar = '#JSGF V1.0; grammar colors; public <color> = ' + colors.join(' | ') + ' ;' | ||
|
||
var recognition = new SpeechRecognition(); | ||
var speechRecognitionList = new SpeechGrammarList(); | ||
speechRecognitionList.addFromString(grammar, 1); | ||
recognition.grammars = speechRecognitionList; | ||
if (SpeechGrammarList) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like this so it could run on Safari too. |
||
// SpeechGrammarList is not currently available in Safari, and does not have any effect in any other browser. | ||
// This code is provided as a demonstration of possible capability. You may choose not to use it. | ||
var speechRecognitionList = new SpeechGrammarList(); | ||
var grammar = '#JSGF V1.0; grammar colors; public <color> = ' + colors.join(' | ') + ' ;' | ||
speechRecognitionList.addFromString(grammar, 1); | ||
recognition.grammars = speechRecognitionList; | ||
} | ||
recognition.continuous = false; | ||
recognition.lang = 'en-US'; | ||
recognition.interimResults = false; | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like a mistake to me. Did you meant to fix the line above?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no, but we could fix it there too. Safari is missing
webkitSpeechGrammarList
and so throws an error unless you check the property on window. It wasn't missingwebkitSpeechRecognition
in the version I tested so I didn't see an error there.