Class: Google::Genai::MusicSession

Inherits:
Object
  • Object
show all
Defined in:
lib/google/genai/live_music.rb

Instance Method Summary collapse

Constructor Details

#initialize(websocket) ⇒ MusicSession



42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/google/genai/live_music.rb', line 42

def initialize(websocket)
  @ws = websocket
  @message_queue = Queue.new
  
  @ws.on :message do |msg|
    @message_queue.push(JSON.parse(msg.data))
  end

  @ws.on :error do |err|
    puts "WebSocket Error: #{err.message}"
  end
end

Instance Method Details

#pauseObject



72
73
74
# File 'lib/google/genai/live_music.rb', line 72

def pause
  _send_control_signal('PAUSE')
end

#playObject



68
69
70
# File 'lib/google/genai/live_music.rb', line 68

def play
  _send_control_signal('PLAY')
end

#receiveObject



84
85
86
# File 'lib/google/genai/live_music.rb', line 84

def receive
  @message_queue.pop
end

#reset_contextObject



80
81
82
# File 'lib/google/genai/live_music.rb', line 80

def reset_context
  _send_control_signal('RESET_CONTEXT')
end

#set_music_generation_config(config:) ⇒ Object



64
65
66
# File 'lib/google/genai/live_music.rb', line 64

def set_music_generation_config(config:)
  @ws.send({ musicGenerationConfig: config }.to_json)
end

#set_weighted_prompts(prompts:) ⇒ Object



55
56
57
58
59
60
61
62
# File 'lib/google/genai/live_music.rb', line 55

def set_weighted_prompts(prompts:)
  message = {
    clientContent: {
      weightedPrompts: prompts.map(&:to_h)
    }
  }
  @ws.send(message.to_json)
end

#stopObject



76
77
78
# File 'lib/google/genai/live_music.rb', line 76

def stop
  _send_control_signal('STOP')
end