Class: OllamaChat::Say
- Inherits:
-
Ollama::Handlers::Say
- Object
- Ollama::Handlers::Say
- OllamaChat::Say
- Defined in:
- lib/ollama_chat/say.rb
Overview
A handler that uses the system's say command to speak response content.
This class extends Ollama::Handlers::Say to provide voice validation against the system's available voices. It ensures that only valid voices are used, falling back to nil if an invalid voice is specified.
Class Method Summary collapse
-
.voices ⇒ Array<String>
Returns a list of available system voices.
Instance Method Summary collapse
-
#initialize(chat:, voice: nil) ⇒ Say
constructor
Initializes a new Say handler.
Constructor Details
#initialize(chat:, voice: nil) ⇒ Say
Initializes a new Say handler.
25 26 27 28 29 |
# File 'lib/ollama_chat/say.rb', line 25 def initialize(chat:, voice: nil) voice && self.class.voices.member?(voice) or voice = nil @chat = chat super(voice:) end |
Class Method Details
.voices ⇒ Array<String>
Returns a list of available system voices.
This method queries the system's say command to retrieve the list of
available voices. If running within RSpec, it returns an empty array to
avoid side effects during testing.
17 18 19 |
# File 'lib/ollama_chat/say.rb', line 17 def self.voices `say -v '?' 2>/dev/null`.lines.map { |l| l[/^(.+?)\s+[a-z]{2}_[a-zA-Z0-9]{2,}/, 1] }.uniq.sort end |