Skip to content
This repository was archived by the owner on Jun 2, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 5 additions & 24 deletions lib/atom-dictation-view.coffee
Original file line number Diff line number Diff line change
@@ -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')
Expand Down Expand Up @@ -39,7 +39,7 @@ class AtomDictationView
destroy: ->
@element.remove()

listen: ->
toggleListening: ->
if not listening
# Clear out the UI stuff
@interimTranscriptElement.textContent = ""
Expand Down Expand Up @@ -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)
9 changes: 8 additions & 1 deletion lib/atom-dictation.coffee
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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()
Expand All @@ -23,4 +26,8 @@ module.exports =
atomDictationViewState: @atomDictationView.serialize()

toggleListening: ->
@atomDictationView.toggleListening()
@atomDictationView.listen()

toggleSpeaking: ->
@speaker.speak()
29 changes: 29 additions & 0 deletions lib/speaker.coffee
Original file line number Diff line number Diff line change
@@ -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