Class: Ollama::Handlers::Say
- Inherits:
-
Object
- Object
- Ollama::Handlers::Say
- Includes:
- Concern
- Defined in:
- lib/ollama/handlers/say.rb
Overview
A handler that uses the system's say command to speak response content.
The Say handler is designed to convert text responses from Ollama API commands into audible speech using the operating system's native text-to-speech capabilities. It supports customization of voice and interactive modes, making it suitable for applications where audio feedback is preferred over visual display.
Instance Attribute Summary collapse
-
#interactive ⇒ TrueClass, ...
readonly
The interactive attribute reader returns the interactive mode setting associated with the object.
-
#voice ⇒ String
readonly
The voice attribute reader returns the voice associated with the object.
Attributes included from Concern
Instance Method Summary collapse
-
#call(response) ⇒ self
The call method processes a response by printing its content to the output stream.
-
#initialize(output: nil, voice: 'Samantha', interactive: nil) ⇒ Say
constructor
The initialize method sets up a new handler instance with the specified output destination and configures voice and interactive settings for text-to-speech functionality.
Methods included from Concern
Constructor Details
#initialize(output: nil, voice: 'Samantha', interactive: nil) ⇒ Say
The initialize method sets up a new handler instance with the specified output destination and configures voice and interactive settings for text-to-speech functionality.
mode setting for speech synthesis, defaults to nil
27 28 29 30 31 32 33 34 35 |
# File 'lib/ollama/handlers/say.rb', line 27 def initialize(output: nil, voice: 'Samantha', interactive: nil) @voice = voice @interactive = interactive super(output:) unless output @output = open_output @output_pid = @output.pid end end |
Instance Attribute Details
#interactive ⇒ TrueClass, ... (readonly)
The interactive attribute reader returns the interactive mode setting associated with the object.
stored in the instance variable
47 48 49 |
# File 'lib/ollama/handlers/say.rb', line 47 def interactive @interactive end |
#voice ⇒ String (readonly)
The voice attribute reader returns the voice associated with the object.
40 41 42 |
# File 'lib/ollama/handlers/say.rb', line 40 def voice @voice end |
Instance Method Details
#call(response) ⇒ self
The call method processes a response by printing its content to the output stream.
This method handles the display of response content by extracting text from the response object and writing it to the configured output stream. It manages the output stream state, reopening it if necessary when it has been closed, and ensures proper handling of streaming responses by closing the output stream when the response indicates completion.
59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/ollama/handlers/say.rb', line 59 def call(response) if @output.closed? wait_output_pid @output = open_output @output_pid = @output.pid end if content = response.response || response.&.content @output.print content end response.done and @output.close self end |