技能图谱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 许可证转载正文(文字未改动;仅省略文件头元数据、将图片显示为链接,超长内容会截断);版权归 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.