1

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[&quot;World&quot;]
if &quot;Background&quot; in world.node_tree.nodes:
    world.node_tree.nodes[&quot;Background&quot;].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)}')

```

  • What exact command did you run? It's not clear to me what exactly you did to get this error. For python module installations please refer to this answer – Harry McKenzie Aug 27 '23 at 02:38
  • This is with running bpy.ops.graph.sound_bake(filepath=file) with correct context. – Devin Gardner Aug 27 '23 at 10:07
  • I've already pip installed soundfile module and i'm loading a sample flac file 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:44
  • I'm using the most recent downloadable version from blender.org: 3.6.2. I have no idea how yours is working and mine isn't working on 3 separate machines on 3 separate OSes. – Devin Gardner Aug 27 '23 at 16:47
  • @HarryMcKenzie I'm also using the direct pip install bpy package, 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
  • when I run >>> print(bpy.app.version_string), I get Blender 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:03
  • I'll have to give that a try. For some reason, when I installed the official 3.6.2, it didn't install bpy. – Devin Gardner Aug 30 '23 at 10:06

1 Answers1

0

I was able to resolve this. I ended up having to install the necessary tools to build the bpy module myself, as some contributors on the GitHub issue I posted about this pointed out that bpy by default is built with no sound support through pip. I was, however, able to modify the cmake config at build_files/cmake/config/bpy_module.cmake and enable sound support before running make bpy.

  • but that doesnt make sense because the bpy i have by default from the official blender release 3.6.2 does have sound support. really weird issue. – Harry McKenzie Aug 31 '23 at 15:01