Finally figured out the fcurve/baking sound thing, for the most part. Now, I'm getting the error in the title. Full traceback is below. I'm running a fresh install of bpy through pip install, I'm running the most recent download from blender.org, and I'm on Windows 10 if that makes a difference.
Error: Compiled without sound support
Traceback (most recent call last):
File "E:\Git\music\blender.py", line 391, in <module>
main(music_file)
File "E:\Git\music\blender.py", line 379, in main
create_centerpiece(file, 16)
File "E:\Git\music\blender.py", line 352, in create_centerpiece
bpy.ops.graph.sound_bake(filepath=file)
File "C:\Users\devin gardner\AppData\Local\Programs\Python\Python310\lib\site-packages\bpy\3.6\scripts\modules\bpy\ops.py", line 113, in __call__
ret = _op_call(self.idname_py(), None, kw)
RuntimeError: Error: Compiled without sound support
Out of curiosity, I moved everything over to my MacBook and it didn't work there either.
Here is my full minimum reproducer code:
"""Generate an audio visualization when passed a .flac file"""
import random
import os
import time
import datetime
import bpy
import bmesh
import soundfile as sf
################################################################
helper functions BEGIN
################################################################
def set_scene_props(fps, frame_count):
"""
Set scene properties
"""
scene = bpy.context.scene
scene.name = 'scene1'
scene.frame_end = frame_count
# set the background to black
world = bpy.data.worlds["World"]
if "Background" in world.node_tree.nodes:
world.node_tree.nodes["Background"].inputs[0].default_value = (0, 0, 0, 1)
scene.render.fps = fps
scene.frame_current = 1
scene.frame_start = 1
def scene_setup(file):
"""
Function to set up scene
"""
print('Setting up scene')
fps = 60
print(f'FPS is {fps}')
sound_file = sf.SoundFile(file)
print(f'Loaded sound_file {file}')
loop_seconds = sound_file.frames / sound_file.samplerate
print(f'loop_seconds set to {loop_seconds}')
frame_count = int(fps * loop_seconds)
print(f'frame_count set to {frame_count}')
seed = 0
if seed:
random.seed(seed)
print('setting scene properties')
set_scene_props(fps, frame_count)
################################################################
helper functions END
################################################################
def create_centerpiece(file):
"""
Function to generate centerpiece
"""
print('creating centerpiece')
# getting context? and object data?
context = bpy.context
obj = context.object
mesh = obj.data
# New bmesh
b_m = bmesh.new()
# load the mesh
b_m.from_mesh(mesh)
cube = bpy.data.objects['Cube']
# setting keyframes
print('setting keyframes')
start_frame = bpy.data.scenes['scene1'].frame_start
end_frame = bpy.data.scenes['scene1'].frame_end
# creating speaker
bpy.ops.object.speaker_add()
speaker = bpy.data.speakers['Speaker']
sound = bpy.data.sounds.load(file)
speaker.sound = sound
cube.keyframe_insert(data_path='scale', frame=1)
cube.keyframe_insert(data_path='scale', frame=end_frame)
action = cube.animation_data.action
fcurves = [fc for fc in action.fcurves if fc.data_path == 'scale']
for fc in action.fcurves:
if fc.data_path == 'scale':
fc.select = True
for window in bpy.context.window_manager.windows:
screen = window.screen
for area in screen.areas:
if area.type == 'VIEW_3D':
bpy.data.objects['Cube'].select_set(True)
current_state = bpy.data.objects['Cube'].select_get()
print(current_state)
bpy.context.view_layer.objects.active = bpy.data.objects['Cube']
fcurve = action.fcurves.find(data_path='scale', index=1)
fcurve.select = True
area_type = area.type
area_ui_type = area.ui_type
area.type = 'GRAPH_EDITOR'
area.ui_type = 'FCURVES'
with bpy.context.temp_override(window=window, area=area):
bpy.ops.graph.sound_bake(filepath=file)
area.type = area_type
area.ui_type = area_ui_type
break
def main(file):
"""
Python code to generate an animated plane
"""
print('RUNNING scene_setup(file)')
scene_setup(file)
print('RUNNING create_centerpiece(file)')
create_centerpiece(file)
if name == "main":
start_time = time.time()
music_file = input('Enter music file path\n> ')
file_path = 'blender.blend'
main(music_file)
print('SAVING FILE')
bpy.ops.wm.save_as_mainfile(filepath=file_path)
print('FILE SAVED')
end_time = time.time()
print(f'total human time elapsed is {datetime.timedelta(seconds=end_time-start_time)}')
```
music_file="C:\\Users\\harry\\Downloads\\sample.flac", it takes quite some time but it finished successfully and i have a cube that is bouncing to the beat of the music. The error you have just means that the particular version of Blender you are using was compiled without the capability to handle sound-related operations, such as the sound baking operation you're trying to perform in your script. What version are you using? I'm using 3.6. – Harry McKenzie Aug 27 '23 at 15:44pip install bpypackage, which per some contributors on the GitHub issue I created doesn't come with audio support. I'm interested, what version of bpy do you have? – Devin Gardner Aug 27 '23 at 20:43>>> print(bpy.app.version_string), I getBlender bpy version: 3.6.0. Why do you manually install bpy? it's already part of the official Blender 3.6.2 LTS download that I have verified has sound support, just stick with that. Probably that is why the environment got messed up. – Harry McKenzie Aug 30 '23 at 06:03bpy. – Devin Gardner Aug 30 '23 at 10:06