Class: RubyLLM::Agents::Speaker::Lexicon

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_llm/agents/audio/speaker.rb

Overview

Pronunciation lexicon class

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeLexicon

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

#pronunciationsObject (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_hObject



274
275
276
# File 'lib/ruby_llm/agents/audio/speaker.rb', line 274

def to_h
  pronunciations.dup
end