# How to add sound to sequencer using python

I want to add music via python. I tried:

bpy.ops.sequencer.sound_strip_add(bpy.ops.sequencer.sound_strip_add(filepath="//mymusic.mp3", frame_start=0, channel=1)


but somehow it gives me the error:

drop file blabla
Traceback (most recent call last):
File "blabla", line 60, in <module>
File "C:\Program Files\Blender Foundation\Blender\2.77\scripts\modules\bpy\ops.py", line 189, in __call__
ret = op_call(self.idname_py(), None, kw)
RuntimeError: Operator bpy.ops.sequencer.sound_strip_add.poll() failed, context is incorrect

Error: Python script fail, look in the console for now...


Any ideas?

• Have a look at blender.stackexchange.com/questions/6101/… In this case you need to be in the 'SEQUENCE_EDITOR' space. – batFINGER Sep 27 '16 at 18:43
• since i dont really want to go there and just add the sound is there no workaround? or can i switch to the editor space with python and then back? – froggyman Sep 27 '16 at 18:44
• scene.sequence_editor.sequences.new_sound(name, filepath, channel, frame_start) – batFINGER Sep 27 '16 at 18:47
• NameError: name 'scene' is not defined – froggyman Sep 27 '16 at 18:50
• – zeffii Sep 28 '16 at 7:05

import bpy