1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-07-31 16:09:28 +02:00

Add script for spectrograms.

This commit is contained in:
James Crook 2018-02-15 19:00:55 +00:00 committed by Paul Licameli
parent 4567f2283a
commit 7b4d55accd
3 changed files with 230 additions and 75 deletions

View File

@ -151,78 +151,63 @@ def addLabels2():
do( 'Select: First=3 Last=3' )
# A stero track with four labels.
def image1() :
def image1and2() :
makeStereoTracks(1)
addLabels()
# A stero track with four labels.
do( "Select: Start=0 End=0" )
capture( 'AutoLabels001.png', 'First_Two_Tracks' )
# Removing a label with delete (fraud - we used split delete)
def image2() :
makeStereoTracks(1)
addLabels()
# Removing a label with delete (fraud - we used split delete)
do( "Select: Start=44.5 End=60.5 First=2 Last=2" )
do( "SplitDelete" )
do( "Select: Start=0 End=0 First=0 Last=2" )
capture( 'AutoLabels002.png','First_Two_Tracks' )
# Removing a label with split-delete step 1
def image3() :
def image3and4() :
makeStereoTracks(1)
addLabels()
# Removing a label with split-delete step 1
do( "Select: Start=44.5 End=60.5 First=2 Last=2" )
capture( 'AutoLabels003.png','First_Two_Tracks' )
# Removing a label with split-delete step 1
def image4() :
makeStereoTracks(1)
addLabels()
# Removing a label with split-delete step 1
do( "Select: Start=44.5 End=60.5 First=2 Last=2" )
do( "SplitDelete" )
capture( 'AutoLabels004.png','First_Two_Tracks' )
def image5() :
def image5and6and7() :
makeStereoTracks(1)
addLabels2()
# Nothing selected
do( "Select: Start=0 End=0" )
capture( 'AutoLabels005.png','First_Three_Tracks' )
def image6() :
makeStereoTracks(1)
addLabels2()
# A range selected in label track.
do( "Select: Start=28.5 End=58.5" )
capture( 'AutoLabels006.png','First_Three_Tracks' )
def image7() :
makeStereoTracks(1)
addLabels2()
do( "Select: Start=28.5 End=58.5" )
# Deleting in label track only.
do( "Delete" )
do( "Select: Start=0 End=0" )
capture( 'AutoLabels007.png','First_Three_Tracks' )
def image8to10() :
def image8and9and10() :
makeStereoTracks(1)
addLabels2()
# Select nothing in all three tracks.
do( "Select: First=2 Last=2 Start=100 End=125" )
do( "AddLabel" )
do( 'SetLabel: Label=9 Text="Clap" selected=0 Start=110 End=118 ')
do( 'Select: First=0 Last=3 Start=0 End=0')
capture( 'AutoLabels008.png','First_Three_Tracks' )
# Select label and all three tracks
do( 'SetLabel: Label=9 Text="Clap" selected=1 Start=110 End=118 ')
do( 'Select: First=0 Last=3 Start=110 End=118')
capture( 'AutoLabels009.png','First_Three_Tracks' )
# Delete label and from all three tracks.
do( 'Delete' )
capture( 'AutoLabels010.png','First_Three_Tracks' )
#quickTest()
setup()
#image1()
#image2()
#image3()
#image4()
#image5()
#image6()
#image7()
image8to10()
image1and2()
image3and4()
image5and6and7()
image8and9and10()

View File

@ -0,0 +1,188 @@
# docimages_spectro.py
# Sends commands to get images for the manual.
# Images for https://alphamanual.audacityteam.org/man/Spectrogram_View
# Make sure Audacity is running first and that mod-script-pipe is enabled
# before running this script.
import os
import sys
if( sys.platform == 'win32' ):
print( "pipe-test.py, running on windows" )
toname = '\\\\.\\pipe\\ToSrvPipe'
fromname = '\\\\.\\pipe\\FromSrvPipe'
EOL = '\r\n\0'
else:
print( "pipe-test.py, running on linux or mac" )
toname = '/tmp/audacity_script_pipe.to.' + str(os.getuid())
fromname = '/tmp/audacity_script_pipe.from.' + str(os.getuid())
EOL = '\n'
print( "Write to \"" + toname +"\"" )
if not os.path.exists( toname ) :
print( " ..does not exist. Ensure Audacity is running with mod-script-pipe." )
sys.exit();
print( "Read from \"" + fromname +"\"")
if not os.path.exists( fromname ) :
print( " ..does not exist. Ensure Audacity is running with mod-script-pipe." )
sys.exit();
print( "-- Both pipes exist. Good." )
tofile = open( toname, 'wt+' )
print( "-- File to write to has been opened" )
fromfile = open( fromname, 'rt')
print( "-- File to read from has now been opened too\r\n" )
def sendCommand( command ) :
print( "Send: >>> \n"+command )
tofile.write( command + EOL )
tofile.flush()
def getResponse() :
result = ''
line = ''
while line != '\n' :
result += line
line = fromfile.readline()
#print(" I read line:["+line+"]")
return result
def doCommand( command ) :
sendCommand( command )
response = getResponse()
print( "Rcvd: <<< \n" + response )
return response
def do( command ) :
doCommand( command )
def quickTest() :
do( 'Help: Command=Help' )
def setup() :
global path
global sample
global sample2
path = 'C:\\Users\\James Crook\\'
sample ='C:\\Users\\James Crook\\Music\\The Poodle Podcast.wav'
sample2 ='C:\\Users\\James Crook\\Music\\PoodlePodStereo.wav'
do( 'SetProject: X=10 Y=10 Width=850 Height=800' )
def makeWayForTracks( ) :
# Twice to remove stereo tracks.
do( 'SelectTracks: First=0 Last=20' )
do( 'RemoveTracks' )
do( 'SelectTracks: First=0 Last=20' )
do( 'RemoveTracks' )
def capture( name, what ) :
global path
do( 'Screenshot: Path="'+path+name+'" CaptureWhat=' + what )
def loadMonoTrack():
global sample
makeWayForTracks( )
do( 'Import2: Filename="'+sample+'"' )
do( 'Select: First=0 Last=0 Start=0 End=150')
do( 'Trim')
do( 'ZoomSel' )
def loadStereoTrack():
global sample2
makeWayForTracks( )
do( 'Import2: Filename="'+sample2+'"' )
do( 'Select: First=0 Last=0 Start=0 End=150')
do( 'Trim')
do( 'ZoomSel' )
def loadMonoTracks( num ) :
makeWayForTracks( )
loadMonoTrack()
do( 'SetTrack: Track=0 Name="Foxy Lady"')
for i in range( 0, num-1 ):
do( 'Duplicate' )
do( 'FitInWindow' )
do( 'Select: Start=55 End=70')
def loadStereoTracks( num ) :
makeWayForTracks( )
loadStereoTrack()
do( 'SetTrack: Track=0 Name="Foxy Lady"')
for i in range( 0, num-1 ):
do( 'Duplicate' )
do( 'FitInWindow' )
do( 'Select: Start=55 End=70 First=0 Last=' + str(num*2-1) )
def makeMonoTracks( num ) :
makeWayForTracks( )
for i in range( 0, num ):
do( 'NewMonoTrack' )
do( 'SetTrack: Track=0 Name="Foxy Lady"')
do( 'Select: Start=0 End=150 First=0 Last=' + str(num-1) )
do( 'Chirp: StartAmp=0.5' )
do( 'Wahwah' )
do( 'FitInWindow' )
do( 'Select: Start=55 End=70')
def makeStereoTracks( num ) :
makeWayForTracks( )
for i in range( 0, num ):
do( 'NewStereoTrack' )
do( 'SetTrack: Track=0 Name="Voodoo Children IN STEREO"')
do( 'Select: Start=0 End=150 First=0 Last=' + str(num*2-1) )
do( 'Chirp: StartAmp=0.5' )
do( 'Wahwah' )
do( 'FitInWindow' )
do( 'Select: Start=55 End=70')
# 11 2KHz tones, of decreasing amplitude.
# With label track to annotate it.
def makeStepper():
makeWayForTracks()
do( 'NewMonoTrack' )
do( 'Select: Start=0 End=22')
do( 'Silence' ) #Just so we can watch.
do( 'FitInWindow')
for i in range( 0, 11 ):
do( 'Select: Start='+str(i*2)+' End='+str(i*2+2) )
do( 'Chirp: StartFreq=2000 EndFreq=2000 StartAmp=' + str( (400**(0.1 * (10-i)))/400 )+' EndAmp=' + str( (400**(0.1 * (10-i) ))/400 ))
do( 'Select: Start=0 End=22')
do( 'Join' )
do( 'FitInWindow')
do( 'AddLabelTrack' )
for i in range( 0, 11 ):
do( 'Select: Start='+str(i*2)+' End='+str(i*2+2) )
do( 'AddLabel' )
do( 'SetLabel: Label=' + str(i)+' Selected=0 Text='+str( -(i*10) ))
do( 'Select: Start=0 End=0')
def image1and2() :
loadStereoTracks(1)
# A stereo track
capture( 'Spectral001.png', 'First_Track' )
# As spectrogram.
do( 'SetTrack: Track=0 Display=Spectrogram')
do( 'SetTrack: Track=1 Display=Spectrogram')
do( 'Select: Start=55 End=70 First=0 Last=1')
capture( 'Spectral002.png', 'First_Track' )
def image3and4():
makeStepper();
# Stepper tone, viewed in dB.
do( 'SetTrack: Scale=dB')
capture( 'Spectral003.png', 'First_Two_Tracks' )
# As spectrogram.
do( 'SetTrack: Display=Spectrogram')
capture( 'Spectral004.png', 'First_Two_Tracks' )
#quickTest()
setup()
image1and2()
image3and4()

View File

@ -118,15 +118,22 @@ def makeStereoTracks( num ) :
do( 'FitInWindow' )
do( 'Select: Start=55 End=70')
# A mono track complete with ruler
def image1() :
def image1and8() :
loadMonoTracks(1)
# A mono track complete with ruler
capture( 'AutoTracks001.png', 'First_Track_Plus' )
# Mono with arrow at start.
do( 'SetClip: Clip=0 Start=-4.0')
capture( 'AutoTracks008.png', 'First_Track' )
# A stereo track, with its name on the track
def image2() :
def image2and6() :
makeStereoTracks(1)
# A stereo track, with its name on the track
capture( 'AutoTracks002.png', 'First_Track' )
# A stereo track, with different sized channels
do( 'SetTrack: Track=0 Height=80')
do( 'SetTrack: Track=1 Height=180')
capture( 'AutoTracks006.png', 'First_Track' )
# Four colours of track
def image3() :
@ -137,16 +144,17 @@ def image3() :
do( 'SetTrack: Track=3 Name="Instrument 4" Height=122 Color=Color3')
capture( 'AutoTracks003.png', 'First_Four_Tracks' )
# Two Tracks, ready to make stereo
def image4():
def image7and4and5():
loadMonoTracks(2)
# Two mono tracks of different sizes
do( 'SetTrack: Track=0 Height=180')
do( 'SetTrack: Track=1 Height=80')
capture( 'AutoTracks007.png', 'First_Two_Tracks' )
# Two Tracks, ready to make stereo
do( 'SetTrack: Track=0 Name="Left Track" Height=80')
do( 'SetTrack: Track=1 Name="Right Track" Height=80')
capture( 'AutoTracks004.png', 'First_Two_Tracks' )
# Mono tracks made stereo
def image5():
loadMonoTracks(2)
# Combined Stereo Track
do( 'SetTrack: Track=0 Pan=-1 Height=80')
do( 'SetTrack: Track=1 Pan=1 Height=80')
do( 'MixAndRender' )
@ -155,51 +163,25 @@ def image5():
do( 'Select: First=0 Last=1' )
capture( 'AutoTracks005.png', 'First_Track' )
# A stereo track, with different sized channels
def image6() :
makeStereoTracks(1)
do( 'SetTrack: Track=0 Height=80')
do( 'SetTrack: Track=1 Height=180')
capture( 'AutoTracks006.png', 'First_Track' )
# Two mono tracks of different sizes
def image7() :
loadMonoTracks(2)
do( 'SetTrack: Track=0 Height=180')
do( 'SetTrack: Track=1 Height=80')
capture( 'AutoTracks007.png', 'First_Two_Tracks' )
# Mono with arrow at start.
def image8() :
loadMonoTracks(1)
do( 'SetClip: Clip=0 Start=-4.0')
capture( 'AutoTracks008.png', 'First_Track' )
# Zoomed in to show points stem-plot
def image9() :
def image9and10() :
#make rather than load. We want an artificial track.
makeMonoTracks(1)
# Zoomed in to show points stem-plot
do( 'Select: Start=0 End=0.003' )
do( 'ZoomSel' );
do( 'Amplify: Ratio=3.0' )
do( 'SetPreference: Name=/GUI/SampleView Value=1 Reload=1')
capture( 'AutoTracks009.png', 'First_Track' )
# Zoomed in to show points stem-plot and then no stem plot
def image9and10() :
image9()
# Zoomed in to show points stem-plot and then no stem plot
do( 'SetPreference: Name=/GUI/SampleView Value=0 Reload=1')
capture( 'AutoTracks010.png', 'First_Track' )
#quickTest()
setup()
image1()
image2()
image1and8()
image2and6()
image3()
image4()
image5()
image6()
image7()
image8()
image7and4and5()
image9and10()