1
$\begingroup$

I am now aware that Blender doesn’t support recording audio natively, but I’ve decided to use Pyaudio somehow. For now I intend to import to VSE, but the real issue for me is displaying “time since record start” in the information panel line (The same one that shows blender version and sometimes progress bars for baking). I’m just not sure at this point if it’s possible.

$\endgroup$
3
  • $\begingroup$ Blender is not intended to be an audio (or video) recorder. You should record your audio with another program and then import it into Blender. docs.blender.org/manual/en/2.79/editors/vse/sequencer/strips/… $\endgroup$
    – John Eason
    Commented May 13, 2023 at 11:34
  • $\begingroup$ Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. $\endgroup$
    – Community Bot
    Commented May 15, 2023 at 7:06
  • $\begingroup$ Thank you for your advice, but I have made positive progress with the addon and can now at least record directly in Blender by clicking a button in the 3d viewport right panel list. I will continue to push because of this even if it seems hopeless at first. $\endgroup$
    – Lockshades
    Commented May 16, 2023 at 12:38

1 Answer 1

0
$\begingroup$

I am building a sound system in Blender too. There are some if not a lot of technical difficulties with sound and using Blender's APIto implement sound for various reasons, but it is not impossible.

The following code will add it to the list that can be triggered in viewport by pressing N, under view/tool/item etc. It will track time while running regardless of how many times is looped and revert to where you are on the timeline for a first loop when you stop recording:

import bpy
import time

# Define a custom property group for recording properties
class RecordingProperties(bpy.types.PropertyGroup):
    start_time: bpy.props.FloatProperty(
        name="Start Time",
        description="The time when the recording started",
        default=0.0,
    )

# Define the UI panel for the recording properties
class RecordingPropertiesPanel(bpy.types.Panel):
    bl_label = "Recording Properties"
    bl_idname = "VIEW3D_PT_recording_properties"
    bl_space_type = "VIEW_3D"
    bl_region_type = "UI"
    bl_category = "Recording"

    @classmethod
    def poll(cls, context):
        return context.scene is not None

    def draw(self, context):
        layout = self.layout
        rec_props = context.scene.rec_props

        row = layout.row()
        row.label(text=f"Time since record start: {time.time() - rec_props.start_time:.2f} seconds")

        row = layout.row()
        row.operator("wm.start_recording")
        row.operator("wm.stop_recording")

class StartRecordingOperator(bpy.types.Operator):
    bl_idname = "wm.start_recording"
    bl_label = "Start Recording"

    def execute(self, context):
        context.scene.rec_props.start_time = time.time()
        context.window_manager.modal_handler_add(self)
        self._timer = context.window_manager.event_timer_add(1.0, window=context.window)
        return {'RUNNING_MODAL'}

    def modal(self, context, event):
        if event.type in {'TIMER'}:
            return {'PASS_THROUGH'}
        return {'RUNNING_MODAL'}

class StopRecordingOperator(bpy.types.Operator):
    bl_idname = "wm.stop_recording"
    bl_label = "Stop Recording"

    def execute(self, context):
        context.window_manager.event_timer_remove(self._timer)
        return {'FINISHED'}

# Register and unregister functions
classes = (RecordingProperties, RecordingPropertiesPanel, StartRecordingOperator, StopRecordingOperator)

def register():
    for cls in classes:
        bpy.utils.register_class(cls)
    bpy.types.Scene.rec_props = bpy.props.PointerProperty(type=RecordingProperties)

def unregister():
    del bpy.types.Scene.rec_props
    for cls in reversed(classes):
        bpy.utils.unregister_class(cls)

if __name__ == "__main__":
    register()

I have it here too in case you need the .py: https://github.com/BrechtCorbeel/Blender-sound-recording-panel-time-tracker-live-update/blob/main/timetracker.py

$\endgroup$
2
  • $\begingroup$ Thanks! I wish to use this with Grease pencil animation. I will definitely give it my all and I've already put my back into this. Thank you so much. $\endgroup$
    – Lockshades
    Commented May 13, 2023 at 16:41
  • $\begingroup$ for no, I'm just focused on a working UI frontend and studying the PYaudio documentation to see what's possible (passively doing small isolated experiments) $\endgroup$
    – Lockshades
    Commented May 13, 2023 at 16:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .