Class: Google::Genai::MusicSession
- Inherits:
-
Object
- Object
- Google::Genai::MusicSession
- Defined in:
- lib/google/genai/live_music.rb
Instance Method Summary collapse
-
#initialize(websocket) ⇒ MusicSession
constructor
A new instance of MusicSession.
- #pause ⇒ Object
- #play ⇒ Object
- #receive ⇒ Object
- #reset_context ⇒ Object
- #set_music_generation_config(config:) ⇒ Object
- #set_weighted_prompts(prompts:) ⇒ Object
- #stop ⇒ Object
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 = Queue.new @ws.on :message do |msg| .push(JSON.parse(msg.data)) end @ws.on :error do |err| puts "WebSocket Error: #{err.message}" end end |
Instance Method Details
#pause ⇒ Object
72 73 74 |
# File 'lib/google/genai/live_music.rb', line 72 def pause _send_control_signal('PAUSE') end |
#play ⇒ Object
68 69 70 |
# File 'lib/google/genai/live_music.rb', line 68 def play _send_control_signal('PLAY') end |
#receive ⇒ Object
84 85 86 |
# File 'lib/google/genai/live_music.rb', line 84 def receive .pop end |
#reset_context ⇒ Object
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:) = { clientContent: { weightedPrompts: prompts.map(&:to_h) } } @ws.send(.to_json) end |
#stop ⇒ Object
76 77 78 |
# File 'lib/google/genai/live_music.rb', line 76 def stop _send_control_signal('STOP') end |