# Play, start & stop recording with sonic pi programmatically (e.g. from python script)

**URL:** <https://in-thread.sonic-pi.net/t/play-start-stop-recording-with-sonic-pi-programmatically-e-g-from-python-script/9116>\
**Category:** Support, Help & Resources\
**Created:** [August 10, 2024, 8:09pm UTC](https://in-thread.sonic-pi.net/t/play-start-stop-recording-with-sonic-pi-programmatically-e-g-from-python-script/9116 "2024-08-10T20:09:44Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jeanke2](https://avatars.discourse-cdn.com/v4/letter/j/f0a364/32.png) [@jeanke2](https://in-thread.sonic-pi.net/u/jeanke2)\
**Post date:** [August 10, 2024, 8:09pm UTC](https://in-thread.sonic-pi.net/t/play-start-stop-recording-with-sonic-pi-programmatically-e-g-from-python-script/9116/1 "2024-08-10T20:09:44Z")

</div>

As sonic Pi sounds can be recorded to WAV files, is this still possible in the latest version of Sonic PI doing this programmatically using OSC?

I am currently on v4.5.1.

Based on older comments (however \<=2018) I was trying out with OSC command from python, I see the logs in the sonic pi cues window, but nothing gets recorded, nor audio can be heared nor a WAV file is saved.

```ruby
from pythonosc.udp_client import SimpleUDPClient
import uuid
import time

# Define the IP and port for Sonic Pi
ip = "192.168.0.206"
port = 4560

# Create the client to send OSC messages
client = SimpleUDPClient(ip, port)

# The song code you want to send to Sonic Pi
song_code = '''
use_bpm 120

live_loop :melody do
  play :c4
  sleep 0.5
  play :e4
  sleep 0.5
  play :g4
  sleep 1
end
'''

# Generate a unique identifier (UUID) for this code run
code_uuid = str(uuid.uuid4())

# Filepath for the recording
output_filename = "Users/USER/test/testfile.wav"

# Start recording
client.send_message('/start-recording', [output_filename])

# Give some time for Sonic Pi to start recording
time.sleep(1)

# Send the song code to Sonic Pi with a unique ID
client.send_message('/run-code-with-uuid', [code_uuid, song_code])

# Duration of the recording (make sure it covers the duration of your code)
recording_duration = 10 # seconds
time.sleep(recording_duration)

# Stop recording
client.send_message('/stop-recording', [])

# Give some time for Sonic Pi to finalize the recording
time.sleep(1)

print(f"Recording saved as {output_filename}")

```
