SkillsGrove
SkillsGrove/動画制作/JAICHANGPARK/flutter_gemini_live/gemini-live-music

gemini-live-music

インストール

$npx skills add https://github.com/JAICHANGPARK/flutter_gemini_live --skill gemini-live-music
$git clone --depth 1 https://github.com/JAICHANGPARK/flutter_gemini_live.git /tmp/flutter_gemini_live && mkdir -p ~/.claude/skills && cp -r /tmp/flutter_gemini_live/.hermes/skills/gemini-live-music ~/.claude/skills/gemini-live-music
この Agent Skill をインストールしてください:https://github.com/JAICHANGPARK/flutter_gemini_live/tree/8e51a205f69168cc37834c8b0193c83a9f270f5c/.hermes/skills/gemini-live-music — まず SKILL.md とスクリプトを読み、安全であることを確認してから、私のスキルフォルダにインストールしてください。

概要

原文の説明 · BSD-3-ClauseImplement real-time steerable music generation using Google's Lyria Live (Realtime Music) model in Flutter. Use when connecting to models/lyria-realtime-exp via genAI.live.music, adjusting weighted prompts (Prompt DJ), setting musical attributes (BPM, musical scale, temperature), controlling playback (play, pause, stop, resetContext), or playing 48kHz stereo PCM audio.
以下の SKILL.md は JAICHANGPARK/flutter_gemini_live(コミット 8e51a20)から BSD-3-Clause ライセンスに基づいて転載しています。本文は変更しておらず、ファイル先頭のメタデータのみ省略し、画像はリンクとして表示し、非常に長いファイルは途中までの表示としています。Copyright 2025, Dreamwalker。ライセンス:LICENSE。表示しているのは指示ファイルのみです。スクリプト等は元のリポジトリをご覧ください。

Gemini Live Music (Lyria Realtime) Skill

This skill provides instructions for generating continuous, steerable real-time music using Google's Lyria Realtime model (models/lyria-realtime-exp) via the gemini_live package.


🎵 Audio Specifications

Parameter Specification Notes
Model ID models/lyria-realtime-exp Realtime interactive music generation.
Output Format Linear PCM (audio/pcm) 16-bit signed Little-Endian.
Sample Rate 48,000 Hz (48 kHz) High fidelity music stream.
Channels 2 (Stereo) Left & right audio channels.
Player Setup Channels.stereo, sampleRate: 48000 Configure in flutter_soloud or Web Audio API.

🎹 Connecting to the Live Music Service

Access the service via genAI.live.music.connect():

import 'dart:typed_data';
import 'package:flutter_soloud/flutter_soloud.dart';
import 'package:gemini_live/gemini_live.dart';

class LiveMusicManager {
  final GoogleGenAI genAI;
  LiveMusicSession? _session;
  AudioSource? _bufferSource;

  LiveMusicManager({required this.genAI});

  Future<void> startMusicStream() async {
    // 1. Initialize Stereo 48kHz Audio Output (via flutter_soloud)
    await SoLoud.instance.init();
    _bufferSource = SoLoud.instance.setBufferStream(
      sampleRate: 48000,
      channels: Channels.stereo, // Stereo playback
      format: BufferType.s16le,
      bufferingType: BufferingType.released,
    );
    await SoLoud.instance.play(_bufferSource!);

    // 2. Connect to Lyria Realtime
    _session = await genAI.live.music.connect(
      LiveMusicConnectParameters(
        model: 'models/lyria-realtime-exp',
        callbacks: LiveMusicCallbacks(
          onOpen: () => print('Music WebSocket connected'),
          onMessage: (LiveMusicServerMessage message) {
            // Incoming 48kHz stereo PCM chunks (also accessible via session.receive() / session.messages)
            if (message.audioBytes != null) {
              SoLoud.instance.addAudioDataStream(_bufferSource!, message.audioBytes!);
            }
          },
          onError: (e, st) => print('Live Music Error: $e'),
          onClose: (code, reason) => print('Closed: $code ($reason)'),
        ),
      ),
    );

    // 3. Start generating initial music
    await _session!.setWeightedPrompts([
      WeightedPrompt(text: 'ambient chill lofi beats', weight: 1.0),
      WeightedPrompt(text: 'gentle rain in the background', weight: 0.5),
    ]);

    await _session!.setMusicGenerationConfig(
      LiveMusicGenerationConfig(
        bpm: 85,
        scale: Scale.C_MAJOR_A_MINOR,
        temperature: 0.7,
      ),
    );

    // 4. Begin playback
    _session!.play();
  }

  /// Update prompt weights dynamically in real-time (Prompt DJ)
  Future<void> updatePromptDJ(double crossfade) async {
    if (_session == null) return;
    // Crossfade between 0.0 (Chill) and 1.0 (Energetic)
    await _session!.setWeightedPrompts([
      WeightedPrompt(text: 'chill lofi beats', weight: 1.0 - crossfade),
      WeightedPrompt(text: 'energetic synthwave bassline', weight: crossfade),
    ]);
  }

  /// Control playback state
  void pause() => _session?.pause();
  void resume() => _session?.play();
  void stop() => _session?.stop();

  /// Reset generation context for dramatic genre shifts
  void resetGenre(String newGenre) {
    _session?.resetContext();
    _session?.setWeightedPrompts([
      WeightedPrompt(text: newGenre, weight: 1.0),
    ]);
  }

  Future<void> dispose() async {
    _session?.stop();
    await _session?.close();
  }
}

🎚️ Musical Attribute Controls

BPM (Tempo)

Tempo can be adjusted between 60 and 180 BPM:

session.setMusicGenerationConfig(
  LiveMusicGenerationConfig(bpm: 128),
);

Musical Scales (Scale Enum)

Supported scales include:

  • Scale.C_MAJOR_A_MINOR
  • Scale.D_MAJOR_B_MINOR
  • Scale.G_MAJOR_E_MINOR
  • Scale.F_MAJOR_D_MINOR
  • Scale.A_MAJOR_F_SHARP_MINOR
  • Scale.SCALE_UNSPECIFIED (allows AI free choice)

Generation Temperature

Values from 0.2 (predictable, stable rhythm) to 1.0 (creative, experimental).

Pre-Built Prompt DJ UI (GeminiLiveMusicControlDeck)

Drop GeminiLiveMusicControlDeck(session: _session) into any screen to get a ready-made Prompt DJ mixer with dynamic weighted prompt sliders, BPM slider, Scale dropdown, and Play/Pause/Stop/Reset transport controls (customizable via headerBuilder, promptItemBuilder, and transportBuilder).


🚨 Critical Music Rules & Anti-Patterns

  1. Ensure Stereo Configuration: Lyria outputs stereo audio (2 channels). Playing it on a mono buffer will play at half speed or double pitch. Always configure output audio players with Channels.stereo and 48,000 Hz.
  2. Use resetContext() when switching genres radically: Lyria maintains musical context continuity. If you transition abruptly from "classical piano" to "heavy drum and bass", call resetContext() to avoid jarring musical dissonance.
  3. Do not confuse Lyria Realtime with TTS models: Lyria is an instrumental and background music model. It does not output speech or transcribe text.
ライセンス全文を見る(BSD-3-Clause)
BSD 3-Clause License

Copyright (c) 2025, Dreamwalker

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
   list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice,
   this list of conditions and the following disclaimer in the documentation
   and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its
   contributors may be used to endorse or promote products derived from
   this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.