Class: RubyLLM::Agents::Speaker::Lexicon
- Inherits:
-
Object
- Object
- RubyLLM::Agents::Speaker::Lexicon
- Defined in:
- lib/ruby_llm/agents/audio/speaker.rb
Overview
Pronunciation lexicon class
Instance Attribute Summary collapse
- #pronunciations ⇒ Object readonly
Instance Method Summary collapse
- #apply(text) ⇒ Object
-
#initialize ⇒ Lexicon
constructor
A new instance of Lexicon.
- #pronounce(word, pronunciation) ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize ⇒ Lexicon
Returns a new instance of Lexicon.
258 259 260 |
# File 'lib/ruby_llm/agents/audio/speaker.rb', line 258 def initialize @pronunciations = {} end |
Instance Attribute Details
#pronunciations ⇒ Object (readonly)
256 257 258 |
# File 'lib/ruby_llm/agents/audio/speaker.rb', line 256 def pronunciations @pronunciations end |
Instance Method Details
#apply(text) ⇒ Object
266 267 268 269 270 271 272 |
# File 'lib/ruby_llm/agents/audio/speaker.rb', line 266 def apply(text) result = text.dup pronunciations.each do |word, pronunciation| result.gsub!(/\b#{Regexp.escape(word)}\b/i, pronunciation) end result end |
#pronounce(word, pronunciation) ⇒ Object
262 263 264 |
# File 'lib/ruby_llm/agents/audio/speaker.rb', line 262 def pronounce(word, pronunciation) @pronunciations[word] = pronunciation end |
#to_h ⇒ Object
274 275 276 |
# File 'lib/ruby_llm/agents/audio/speaker.rb', line 274 def to_h pronunciations.dup end |