Author Topic: cutting the soundfile  (Read 7598 times)

wip

  • Newbie
  • *
  • Posts: 1
    • View Profile
cutting the soundfile
« on: February 03, 2008, 22:29:40 »
hi,

i would like to use sonicvisualiser (nice software by the way) to cut a wav. using add new time instants layer, i am able to specify where i want to cut the soundfile (in segmentation mode).

the question is: is there a script / plug-in or a way to take this annotation file and process my soundfile (cutting the sf using the frame)? if not, i will write a python script, but i don't want to rewrite something.

here's something working, but very basic:


Code: [Select]
"""
Sonic Visualiser Splicer
Patrick Sebastien Coulombe

using New Time Instants Layer - Segmentation Plot
exporting in Sonic Visualiser Layer XML
"""
import wave
from xml.dom import minidom

"""
EDIT
"""
svl = "cutam.svl"
sf = "amen.wav"


xmldoc = minidom.parse(svl)

sfwo = wave.open(sf, "r")
nchannels, sampwidth, framerate, nframes, comptype, compname = sfwo.getparams()

i = 0
for ref in xmldoc.getElementsByTagName('point'):
if i == 0:
global position
print "---Position---"
position = ref.attributes["frame"].value
sfwo.setpos(int(position))
i = 1
else:
print "---Splice---"
frame = int(ref.attributes["frame"].value) - int(position)
data = sfwo.readframes(int(frame))
sfww = sf[0:-4]+"_"+ref.attributes["label"].value+".wav"
fo = wave.open(sfww, "w")
fo.setparams((nchannels, sampwidth, framerate, 0, comptype, compname))
fo.writeframes(data)
fo.close()
print sfww
print
i = 0
sfwo.close()

thanks!
pat
« Last Edit: February 04, 2008, 06:29:55 by wip »

cannam

  • Administrator
  • Sr. Member
  • *****
  • Posts: 273
    • View Profile
Re: cutting the soundfile
« Reply #1 on: February 04, 2008, 12:43:48 »
This may be stating the obvious, but since you didn't mention it: you can export just the selected area as a new audio file straight from Sonic Visualiser, thus effectively slicing it without leaving SV.

File -> Export Audio File will offer the option of exporting just the selected region, if there is a selection active.  If there are multiple selections, you can choose whether to export them to multiple files or splice them together into a single file.

Apart from this feature, I don't know of any other way to achieve what you want with an existing, ready-made script or program.


Chris

tjcrone

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: cutting the soundfile
« Reply #2 on: May 19, 2009, 01:48:07 »
Not sure if this is possible entirely within SV, but if you note the start and end time of your selection, you can use a utility like SoX to slice the sound file: http://sox.sourceforge.net/. Hope this helps.