Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
python 3.11.7
Binary file added bandlab_clean.mid
Binary file not shown.
Binary file added bandlab_cool_groove.mid
Binary file not shown.
Binary file added bandlab_drums.mid
Binary file not shown.
Binary file added bandlab_groove.mid
Binary file not shown.
Binary file added clap.wav
Binary file not shown.
87 changes: 87 additions & 0 deletions cua.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
from computer import Computer
import asyncio
import logging
from pathlib import Path
from agent import ComputerAgent


async def computer_use_agent(midi_file='./hum_basic_pitch.mid', instrument='piano'):
"""
Main async function that handles the computer automation.
This function:
1. Reads the MIDI file created from your humming
2. Connects to a cloud computer environment
3. Uploads the MIDI file to the remote computer
"""
# Read the MIDI file that was generated from your humming
midi_file = open(midi_file, "rb")
content = midi_file.read()
midi_file.close()

print("📁 MIDI file loaded successfully")
print(f"📊 File size: {len(content)} bytes")

# Connect to the cloud computer environment
async with Computer(
os_type="linux", # Using Linux environment
provider_type="cloud", # Cloud-based computer
name="l-linux-x318jdeu72", # Specific instance name
api_key=""
) as computer:
print("🖥️ Connected to cloud computer")

# Start the computer interface
await computer.run()
print("▶️ Computer interface started")

# Upload the MIDI file to the remote computer
await computer.interface.write_bytes("~/Downloads/midi-file-name.midi", content)
print("✅ MIDI file uploaded to ~/Downloads/midi-file-name.midi")
midi_name = "midi-file-name.midi"


agent = ComputerAgent(
model="anthropic/claude-opus-4-20250514",
tools=[computer],
max_trajectory_budget=5.0
)
tasks = [f"""
You are inside BandLab Studio in Firefox on Linux.

Goal: Import the MIDI file and play it with the chosen instrument.

FILE TO IMPORT: "~/Downloads/midi-file-name.midi"
FILE NAME ONLY:
INSTRUMENT: {instrument}

Do the following step by step:

1. Click the dashed box in the timeline that says “Drop a loop or an audio/MIDI/video file”.
- This should open a file upload dialog.

2. In the file dialog:
- Click “Downloads” in the sidebar.
- Find and double-click “{midi_name}”.
- If it’s not visible, type “{midi_name}” into the filename field and press Enter.
- Wait until the MIDI region appears on the timeline.
- Take a screenshot.

Rules:
- Always interact inside BandLab, not the browser’s URL bar.
- Use precise clicks; scroll if needed.
"""]

for i, task in enumerate(tasks):
print(f"\nExecuting task {i}/{len(tasks)}: {task}")
async for result in agent.run(task):
print(result)
print(f"\n✅ Task {i+1}/{len(tasks)} completed: {task}")





# This ensures the main function runs when the script is executed
# It properly handles the async/await syntax
if __name__ == "__main__":
asyncio.run(computer_use_agent())
Binary file added drum_groove.mid
Binary file not shown.
Binary file added drum_groove_1757801992.mid
Binary file not shown.
65 changes: 65 additions & 0 deletions drum_midi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import librosa
import pretty_midi
import sounddevice as sd
import soundfile as sf

def record_claps(filename="clap.wav", duration=8, samplerate=44100):
"""Record clapping audio from mic."""
print(f"🎙️ Recording {duration} seconds... Clap steadily (like 1-2-3-4)!")
audio = sd.rec(int(duration * samplerate), samplerate=samplerate, channels=1, dtype="float32")
sd.wait()
sf.write(filename, audio, samplerate)
print(f"✅ Saved recording to {filename}")
return filename

def clap_to_drum_groove(wav_file, out_midi="drum_groove.mid"):
"""Use clapping as tempo guide, generate a clean 4/4 drum groove."""
# Load clap audio
y, sr = librosa.load(wav_file)

# Estimate tempo
tempo, _ = librosa.beat.beat_track(y=y, sr=sr)
if hasattr(tempo, "__len__"): # sometimes returns array
tempo = float(tempo[0])
else:
tempo = float(tempo)

print(f"🎵 Detected tempo: {tempo:.1f} BPM")

# MIDI setup
pm = pretty_midi.PrettyMIDI(initial_tempo=tempo)
drums = pretty_midi.Instrument(program=0, is_drum=True)

beat_len = 60.0 / tempo # seconds per beat
num_bars = 8 # how many bars to generate
total_beats = num_bars * 4

for i in range(total_beats):
t = i * beat_len
beat = i % 4

# Kick on 1 & 3
if beat == 0 or beat == 2:
drums.notes.append(pretty_midi.Note(110, 36, t, t+0.1)) # Kick drum

# Snare on 2 & 4
if beat == 1 or beat == 3:
drums.notes.append(pretty_midi.Note(110, 38, t, t+0.1)) # Snare drum

# Hi-hats every 8th note
for off in [0.0, 0.5]:
drums.notes.append(pretty_midi.Note(85, 42, t + off*beat_len, t + off*beat_len + 0.05))

pm.instruments.append(drums)
pm.write(out_midi)
print(f"🥁 Drum groove saved as: {out_midi}")
return out_midi

if __name__ == "__main__":
# Step 1: Record your claps (used to detect tempo)
wav = record_claps("clap.wav", duration=8)

# Step 2: Generate structured groove MIDI
midi_file = clap_to_drum_groove(wav, "drum_groove.mid")

print("✅ Import 'drum_groove.mid' into BandLab, assign a drum kit, and enjoy a real groove!")
49 changes: 49 additions & 0 deletions hum.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import sounddevice as sd
import soundfile as sf
import numpy as np
import time
def record_hum(output_file="hum.wav", instrument="piano", samplerate=44100, channels=1, silence_thresh=0.01, min_silence_len=2):
time.sleep(3)
print("🎤 Ready. Start humming...")

recording = []
silence_counter = 0
chunk_size = int(samplerate * 0.1) # 100ms chunks

with sd.InputStream(samplerate=samplerate, channels=channels) as stream:
while True:
chunk, _ = stream.read(chunk_size)
chunk = chunk.copy()
recording.append(chunk)

volume = np.abs(chunk).mean()
if volume < silence_thresh:
silence_counter += 1
else:
silence_counter = 0

if silence_counter > min_silence_len * 10: # e.g. 2s silence
break

recording = np.concatenate(recording, axis=0)
sf.write(output_file, recording, samplerate)
print(f"✅ Saved recording to {output_file}")

# Route to appropriate MIDI generator based on instrument
print(f"🎵 Processing for instrument: {instrument}")

if instrument.lower() in ["drums", "drum", "percussion"]:
# Use drum_midi.py for drum processing
print("🥁 Using drum MIDI generator...")
from drum_midi import clap_to_drum_groove
midi_file = clap_to_drum_groove(output_file, f"drum_groove_{int(time.time())}.mid")
return midi_file
else:
# Use midi.py for melodic instruments (piano, guitar, etc.)
print(f"🎹 Using melodic MIDI generator for {instrument}...")
from midi import convert_to_midi
midi_file = convert_to_midi(output_file, ".")
return midi_file

if __name__ == "__main__":
record_hum()
Binary file added hum.wav
Binary file not shown.
4 changes: 4 additions & 0 deletions hum_1757800363_basic_pitch.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
start_time_s,end_time_s,pitch_midi,velocity,pitch_bend
8.840328344671201,9.014478004535148,60,70,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2
3.9602861678004535,4.100889795918367,59,58,5,2,1,1,1,1,1,1,1,1,0,0,0
1.1029478458049886,1.242267573696145,54,56,1,1,1,1,1,1,1,1,1,1,1,2
Binary file added hum_1757800363_basic_pitch.mid
Binary file not shown.
Binary file added hum_1757801953.wav
Binary file not shown.
1 change: 1 addition & 0 deletions hum_1757801953_1757801960_basic_pitch.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
start_time_s,end_time_s,pitch_midi,velocity,pitch_bend
Binary file added hum_1757801953_1757801960_basic_pitch.mid
Binary file not shown.
Binary file added hum_1757801981.wav
Binary file not shown.
21 changes: 21 additions & 0 deletions hum_basic_pitch.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
start_time_s,end_time_s,pitch_midi,velocity,pitch_bend
6.296459410430839,6.482219047619048,47,71,2,2,2,2,1,0,0,0,0,1,1,1,1,2,2,2
5.923656235827664,6.064259863945578,47,62,0,1,0,0,0,0,0,0,0,0,0,0,0
5.71467664399093,5.923656235827664,47,47,2,2,0,0,0,2,2,-1,-1,1,1,1,1,1,1,1,1,0
5.308327437641723,5.645016780045351,50,83,0,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
5.1690077097505664,5.308327437641723,50,55,0,0,0,0,0,-1,-1,-1,-1,-1,-1,0
4.960028117913832,5.110957823129252,52,57,0,0,1,1,1,2,3,3,3,3,3,2,2
4.623338775510204,4.785878458049886,53,86,2,2,1,1,1,1,1,1,1,1,1,1,1,1
4.228599546485261,4.623338775510204,53,67,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,2
3.9138462585034013,4.042839909297052,52,66,2,2,2,2,2,2,2,2,2,2,2,3
3.3449573696145123,3.820966439909297,51,67,3,2,2,0,0,0,0,0,0,0,0,0,0,0,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
2.8689482993197277,3.252077551020408,49,90,0,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,3,3
2.2768394557823126,2.590308843537415,54,56,-1,-1,0,0,0,0,0,0,0,0,0,-1,-1,-1,-1,-1,-1,-1,-1,0,0,0,0,0,0,0,-1
2.091079818594104,2.2768394557823126,53,98,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
1.8808163265306121,2.021419954648526,56,78,0,0,0,0,0,0,0,0,0,0,0,-1,-1
1.6718367346938776,1.8808163265306121,54,85,2,2,1,1,1,1,1,1,1,1,1,1,1,1,2,2,1,1
1.509297052154195,1.6950566893424037,56,90,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,-4
1.1145578231292517,1.509297052154195,56,95,0,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1
0.9520181405895691,1.1145578231292517,56,103,-1,0,0,0,1,1,1,1,1,1,1,1,1,1
0.8010884353741496,0.9520181405895691,55,99,1,1,1,1,1,1,1,1,1,1,1,1,2
4.042839909297052,4.216989569160997,53,81,0,0,0,0,0,1,1,1,1,1,1,1,0,0,0
Binary file added hum_basic_pitch.mid
Binary file not shown.
1 change: 1 addition & 0 deletions instrument.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Drums
Binary file added instrument.wav
Binary file not shown.
35 changes: 35 additions & 0 deletions listen.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Import the server SDK which works with Node.js (not browser-only like @vapi-ai/web)
import { VapiClient } from '@vapi-ai/server-sdk';

// Initialize Vapi client with your API key
const vapi = new VapiClient({
apiKey: '1910ede1-e8f5-4c5e-aba2-deb03c53c9db'
});

console.log('🤖 Vapi server SDK initialized successfully!');

// Async function to handle API calls
async function testVapi() {
// Example: Create a call using the server SDK
// This is different from the web SDK - server SDK is for managing calls, not direct voice interaction
try {
const call = await vapi.calls.create({
assistant: {
id: 'a6210139-4abf-4ed8-b1a5-0996953045b3'
},
// For server SDK, you typically need to specify how to connect (phone, etc.)
customer: {
number: '+1234567890' // This would be the customer's phone number
}
});

console.log('📞 Call created:', call.id);
} catch (error) {
console.log('ℹ️ Note: Server SDK is for managing calls, not direct voice interaction');
console.log('For direct voice interaction, you need a web browser environment');
console.log('Error details:', error.message);
}
}

// Run the test
testVapi();
Loading