Skip to content

Commit

Permalink
table of voices, with default one initially selected
Browse files Browse the repository at this point in the history
  • Loading branch information
drnic committed Dec 29, 2008
1 parent df1100b commit a8a78b9
Show file tree
Hide file tree
Showing 3 changed files with 292 additions and 19 deletions.
33 changes: 29 additions & 4 deletions SpeakLine/Classes/SpeechController.rb
Expand Up @@ -8,33 +8,58 @@

class SpeechController
attr_accessor :textField, :startButton, :stopButton
attr_accessor :speechSynth
attr_accessor :speechSynth, :voicesTableView
attr_accessor :voiceList

def initialize
@speechSynth = NSSpeechSynthesizer.alloc.initWithVoice(nil)
@voiceList = NSSpeechSynthesizer.availableVoices
speechSynth.delegate = self
end

def awakeFromNib
stopButton.enabled = false
defaultVoice = NSSpeechSynthesizer.defaultVoice
defaultRow = voiceList.indexOfObject(defaultVoice)
voicesTableView.selectRow(defaultRow, byExtendingSelection: false)
voicesTableView.scrollRowToVisible(defaultRow)
end

def sayIt(sender)
if textField.stringValue.size > 0
speechSynth.startSpeakingString(textField.stringValue)
stopButton.enabled = true
startButton.enabled = false
stopButton.enabled = true
startButton.enabled = false
voicesTableView.enabled = false
end
end

def stopIt(sender)
speechSynth.stopSpeaking
stopButton.enabled = false
startButton.enabled = true
voicesTableView.enabled = true
end

def speechSynthesizer(sender, didFinishSpeaking: success)

stopButton.enabled = false
startButton.enabled = true
voicesTableView.enabled = true
end

def numberOfRowsInTableView(aTableView)
voiceList.count
end

def tableView(aTableView, objectValueForTableColumn: aTableColumn, row: rowIndex)
voice = voiceList.objectAtIndex(rowIndex)
NSSpeechSynthesizer.attributesForVoice(voice).objectForKey:"VoiceName"
end

def tableViewSelectionDidChange(aNotification)
return if voicesTableView.selectedRow == -1
speechSynth.voice = voiceList.objectAtIndex(voicesTableView.selectedRow)
end


end

0 comments on commit a8a78b9

Please sign in to comment.