From f0d2f841bada3fdc2ecb0e5340f018a47dabb939 Mon Sep 17 00:00:00 2001 From: James R Sconfitto Date: Fri, 10 Apr 2015 13:03:27 -0400 Subject: [PATCH 1/3] Add ability to speak the current tab's text --- lib/atom-dictation-view.coffee | 19 ------------------- lib/atom-dictation.coffee | 8 +++++++- lib/speaker.coffee | 29 +++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 20 deletions(-) create mode 100644 lib/speaker.coffee diff --git a/lib/atom-dictation-view.coffee b/lib/atom-dictation-view.coffee index 5d1be11..2c2dbc8 100644 --- a/lib/atom-dictation-view.coffee +++ b/lib/atom-dictation-view.coffee @@ -86,22 +86,3 @@ class AtomDictationView @finalTranscriptElement.textContent += finalTranscript @interimTranscriptElement.textContent = interimTranscript - -# speak: -> -# console.log 'AtomDictationView is speaking!' -# -# if not speaking -# console.log "Speaking to you!" -# else -# console.log "Done speaking to you!" -# -# # Create message element -# message = document.createElement('div') -# message.textContent = "The AtomDictation package about to speak to you!" -# message.classList.add('message') -# @element.appendChild(message) -# -# # if @element.parentElement? -# # @element.remove() -# # else -# # atom.workspaceView.append(@element) diff --git a/lib/atom-dictation.coffee b/lib/atom-dictation.coffee index f756193..45c3a28 100644 --- a/lib/atom-dictation.coffee +++ b/lib/atom-dictation.coffee @@ -1,11 +1,14 @@ AtomDictationView = require './atom-dictation-view' +Speaker = require './speaker' {CompositeDisposable} = require 'atom' module.exports = atomDictationView: null + speaker: null activate: (state) -> @atomDictationView = new AtomDictationView(state.atomDictationViewState) + @speaker = new Speaker() # Events subscribed to in atom's system can be easily cleaned up with a CompositeDisposable @subscriptions = new CompositeDisposable @@ -14,7 +17,7 @@ module.exports = @subscriptions.add atom.commands.add 'atom-workspace', 'atom-dictation:listen': => @toggleListening() # Register command that reads starting from the cursor - # @subscriptions.add atom.commands.add 'atom-workspace', 'atom-dictation:speak': => @toggleSpeaking() + @subscriptions.add atom.commands.add 'atom-workspace', 'atom-dictation:speak': => @toggleSpeaking() deactivate: -> @atomDictationView.destroy() @@ -24,3 +27,6 @@ module.exports = toggleListening: -> @atomDictationView.listen() + + toggleSpeaking: -> + @speaker.speak() diff --git a/lib/speaker.coffee b/lib/speaker.coffee new file mode 100644 index 0000000..779a579 --- /dev/null +++ b/lib/speaker.coffee @@ -0,0 +1,29 @@ +{CompositeDisposable} = require 'atom' + +module.exports = +class Speaker + speaking = false + currentUtterance = null + + constructor: (serializeState) -> + + speak: -> + if not speaking + if editor = atom.workspace.getActiveTextEditor() + text = editor.getText() + currentUtterance = new SpeechSynthesisUtterance(text) + currentUtterance.on('') + speechSynthesis.speak(currentUtterance); + + console.log "Speaking to you!" + + else + if message + message.cancel() + console.log "Done speaking to you!" + + # Toggle the state + speaking = !speaking + + speechFinished: -> + speaking = false From 059124560bdd12d93b32af90057e5c26942005b5 Mon Sep 17 00:00:00 2001 From: James R Sconfitto Date: Fri, 10 Apr 2015 13:03:43 -0400 Subject: [PATCH 2/3] Rearrange variables --- lib/atom-dictation-view.coffee | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/atom-dictation-view.coffee b/lib/atom-dictation-view.coffee index 2c2dbc8..0e733ae 100644 --- a/lib/atom-dictation-view.coffee +++ b/lib/atom-dictation-view.coffee @@ -1,9 +1,9 @@ -recognition = {} -speaking = false -listening = false - module.exports = class AtomDictationView + recognition = {} + speaking = false + listening = false + constructor: (serializeState) -> # Create root element @element = document.createElement('div') From b28a6620b2efc89b10fb333e4f4936e02d9cfd81 Mon Sep 17 00:00:00 2001 From: James R Sconfitto Date: Fri, 10 Apr 2015 13:13:25 -0400 Subject: [PATCH 3/3] Change listening method's name --- lib/atom-dictation-view.coffee | 2 +- lib/atom-dictation.coffee | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/atom-dictation-view.coffee b/lib/atom-dictation-view.coffee index 5d1be11..ded5e7b 100644 --- a/lib/atom-dictation-view.coffee +++ b/lib/atom-dictation-view.coffee @@ -39,7 +39,7 @@ class AtomDictationView destroy: -> @element.remove() - listen: -> + toggleListening: -> if not listening # Clear out the UI stuff @interimTranscriptElement.textContent = "" diff --git a/lib/atom-dictation.coffee b/lib/atom-dictation.coffee index f756193..d7572d2 100644 --- a/lib/atom-dictation.coffee +++ b/lib/atom-dictation.coffee @@ -23,4 +23,4 @@ module.exports = atomDictationViewState: @atomDictationView.serialize() toggleListening: -> - @atomDictationView.listen() + @atomDictationView.toggleListening()