Exemplo n.º 1
0
def encodeMp3(src, dstDir=None, br=128, title='', 
                    artist='', album='', year='', dstName=None, quality=2):
    """encode an mp3 using lame
    -m s     # stereo mode, not using joint stereo
    -q 2     # quality, 0 creates best quality, 2 is good
    -b 128 # bitrate, 96, 128, 256, 320
    --cbr    # forces constatn bit rate, default
    --disptime n # update more often
    -c       # ha!
    --tt     # title 
    --ta     # artist
    --tl     # album 
    --ty     # year """
    srcDir, srcName = os.path.split(src)
    srcName, ext = osTools.extSplit(srcName)
    
    # optional dstName will be used instead of the srcName mod if provided
    if dstName == None:
        dstName = srcName + '.mp3'
    if dstDir == None or not os.path.isdir(dstDir): #place in same dir
        dst = os.path.join(srcDir, dstName)
    else: # use provided dstdir
        dst = os.path.join(dstDir, dstName)
    tagStr = '--tt "%s" --ta "%s" --tl "%s" --ty "%s" ' % (title, artist, 
                                                           album, year)
    cmd = 'lame -m s -q %s --add-id3v2 --cbr --disptime 1 -b %s -c %s %s %s' % (quality, br, 
                                                            tagStr, src, dst)
    os.system(cmd)
    return dst
Exemplo n.º 2
0
 def __init__(self, src, steps=999, bitRateArray=[64]):
     """encode and re-encode, appending to a file cyclically"""
     self.steps = steps
     self.bitRateArray = bitRateArray
     self.src = src
     self.dir, name = os.path.split(src)
     self.nameStub, ext = osTools.extSplit(name)
Exemplo n.º 3
0
def encodeMp3(src, dstDir=None, br=128, title='', 
                    artist='', album='', year='', dstName=None, quality=2):
    """encode an mp3 using lame
    -m s     # stereo mode, not using joint stereo
    -q 2     # quality, 0 creates best quality, 2 is good
    -b 128 # bitrate, 96, 128, 256, 320
    --cbr    # forces constatn bit rate, default
    --disptime n # update more often
    -c       # ha!
    --tt     # title 
    --ta     # artist
    --tl     # album 
    --ty     # year """
    srcDir, srcName = os.path.split(src)
    srcName, ext = osTools.extSplit(srcName)
    
    # optional dstName will be used instead of the srcName mod if provided
    if dstName == None:
        dstName = srcName + '.mp3'
    if dstDir == None or not os.path.isdir(dstDir): #place in same dir
        dst = os.path.join(srcDir, dstName)
    else: # use provided dstdir
        dst = os.path.join(dstDir, dstName)
    tagStr = '--tt "%s" --ta "%s" --tl "%s" --ty "%s" ' % (title, artist, 
                                                           album, year)
    cmd = 'lame -m s -q %s --add-id3v2 --cbr --disptime 1 -b %s -c %s %s %s' % (quality, br, 
                                                            tagStr, src, dst)
    os.system(cmd)
    return dst
Exemplo n.º 4
0
def encodeAac(src, dstDir=None, br=128, title='', 
                    artist='', album='', year='', dstName=None):
    """encode an ac4 using faac
    note: this does not work w/ aiff files
  --artist X     Set artist to X
  --writer X     Set writer to X
  --title X      Set title to X
  --genre X      Set genre to X
  --album X      Set album to X
  --compilation Set compilation
  --track X      Set track to X (number/total)
  --disc X       Set disc to X (number/total)
  --year X       Set year to X
  --cover-art X Read cover art from file X
  --comment X    Set comment to X
  """
    srcDir, srcName = os.path.split(src)
    srcName, ext = osTools.extSplit(srcName)
    
    # optional dstName will be used instead of the srcName mod if provided
    if dstName == None:
        dstName = srcName + '.m4a'
    if dstDir == None or not os.path.isdir(dstDir): #place in same dir
        dst = os.path.join(srcDir, dstName)
    else: # use provided dstdir
        dst = os.path.join(dstDir, dstName)

    # quality seems to be anywhere from 50 to 150
    tagStr = '--title "%s" --artist "%s" --album "%s" --year "%s" ' % (title, 
                artist, album, year)
    cmd = 'faac -q 100 -b %s %s -o "%s" %s' % (br, tagStr, dst, src)
    os.system(cmd)
    return dst
Exemplo n.º 5
0
def decodeMp3(src, dstDir=None, dstName=None, quality=2):
    """decode an mp3 to wav 
    -m s     # stereo mode, not using joint stereo
    -q 2     # quality, 0 creates best quality, 2 is good
    -b 128 # bitrate, 96, 128, 256, 320
    --cbr    # forces constatn bit rate, default
    --disptime n # update more often
    -c       # ha!
    --tt     # title 
    --ta     # artist
    --tl     # album 
    --ty     # year """
    srcDir, srcName = os.path.split(src)
    srcName, ext = osTools.extSplit(srcName)
    
    # optional dstName will be used instead of the srcName mod if provided
    if dstName == None:
        dstName = srcName + '.wav'
    if dstDir == None or not os.path.isdir(dstDir): #place in same dir
        dst = os.path.join(srcDir, dstName)
    else: # use provided dstdir
        dst = os.path.join(dstDir, dstName)
    cmd = 'lame -m s -q %s --decode --disptime 1 -c %s %s' % (quality, src, dst)
    os.system(cmd)
    return dst
Exemplo n.º 6
0
def decodeMp3(src, dstDir=None, dstName=None, quality=2):
    """decode an mp3 to wav 
    -m s     # stereo mode, not using joint stereo
    -q 2     # quality, 0 creates best quality, 2 is good
    -b 128 # bitrate, 96, 128, 256, 320
    --cbr    # forces constatn bit rate, default
    --disptime n # update more often
    -c       # ha!
    --tt     # title 
    --ta     # artist
    --tl     # album 
    --ty     # year """
    srcDir, srcName = os.path.split(src)
    srcName, ext = osTools.extSplit(srcName)
    
    # optional dstName will be used instead of the srcName mod if provided
    if dstName == None:
        dstName = srcName + '.wav'
    if dstDir == None or not os.path.isdir(dstDir): #place in same dir
        dst = os.path.join(srcDir, dstName)
    else: # use provided dstdir
        dst = os.path.join(dstDir, dstName)
    cmd = 'lame -m s -q %s --decode --disptime 1 -c %s %s' % (quality, src, dst)
    os.system(cmd)
    return dst
Exemplo n.º 7
0
def encodeAac(src, dstDir=None, br=128, title='', 
                    artist='', album='', year='', dstName=None):
    """encode an ac4 using faac
    note: this does not work w/ aiff files
  --artist X     Set artist to X
  --writer X     Set writer to X
  --title X      Set title to X
  --genre X      Set genre to X
  --album X      Set album to X
  --compilation Set compilation
  --track X      Set track to X (number/total)
  --disc X       Set disc to X (number/total)
  --year X       Set year to X
  --cover-art X Read cover art from file X
  --comment X    Set comment to X
  """
    srcDir, srcName = os.path.split(src)
    srcName, ext = osTools.extSplit(srcName)
    
    # optional dstName will be used instead of the srcName mod if provided
    if dstName == None:
        dstName = srcName + '.m4a'
    if dstDir == None or not os.path.isdir(dstDir): #place in same dir
        dst = os.path.join(srcDir, dstName)
    else: # use provided dstdir
        dst = os.path.join(dstDir, dstName)

    # quality seems to be anywhere from 50 to 150
    tagStr = '--title "%s" --artist "%s" --album "%s" --year "%s" ' % (title, 
                artist, album, year)
    cmd = 'faac -q 100 -b %s %s -o "%s" %s' % (br, tagStr, dst, src)
    os.system(cmd)
    return dst
Exemplo n.º 8
0
 def __init__(self, src, steps=999, bitRateArray=[64]):
     """encode and re-encode, appending to a file cyclically"""
     self.steps = steps
     self.bitRateArray = bitRateArray
     self.src = src
     self.dir, name = os.path.split(src)
     self.nameStub, ext = osTools.extSplit(name)
Exemplo n.º 9
0
def soxSpeed(src, dst=None, speed=.5):
    # this is destructive if dst id none
    if dst == None: # replace original
        nameStub, ext = osTools.extSplit(src)
        dst = '%s-temp%s' % (nameStub, ext)
    #print 'in, out, total:', timeIn, timeOut, timeTotal
    # t is a linear slope
    cmd = 'sox %s %s speed %s' % (src, dst, speed)
    os.system(cmd)
    if dst == '%s-temp%s' % (nameStub, ext):
        osTools.mv(dst, src)
        #osTools.rm(dst)
    return src
Exemplo n.º 10
0
def soxSpeed(src, dst=None, speed=.5):
    # this is destructive if dst id none
    if dst == None: # replace original
        nameStub, ext = osTools.extSplit(src)
        dst = '%s-temp%s' % (nameStub, ext)
    #print 'in, out, total:', timeIn, timeOut, timeTotal
    # t is a linear slope
    cmd = 'sox %s %s speed %s' % (src, dst, speed)
    os.system(cmd)
    if dst == '%s-temp%s' % (nameStub, ext):
        osTools.mv(dst, src)
        #osTools.rm(dst)
    return src
Exemplo n.º 11
0
def soxFade(src, dst=None, timeIn=.01, timeOut=.01):
    # add a fade in and fade out to sound file
    # need total time 
    # this is destructive if dst id none
    timeTotal = fileDur(src)
    if dst == None: # replace original
        nameStub, ext = osTools.extSplit(src)
        dst = '%s-temp%s' % (nameStub, ext)
    #print 'in, out, total:', timeIn, timeOut, timeTotal
    # t is a linear slope
    cmd = 'sox %s %s fade t %s %s %s' % (src, dst, timeIn, timeTotal, timeOut)
    os.system(cmd)
    if dst == '%s-temp%s' % (nameStub, ext):
        osTools.mv(dst, src)
        #osTools.rm(dst)
    return src
Exemplo n.º 12
0
def decodeFlac(src, dstDir=None, dstName=None):
    """To decode:
  flac -d [INPUTFILE [...]] """
    srcDir, srcName = os.path.split(src)
    srcName, ext = osTools.extSplit(srcName)
    
    # optional dstName will be used instead of the srcName mod if provided
    if dstName == None:
        dstName = srcName + '.aif'
    if dstDir == None or not os.path.isdir(dstDir): #place in same dir
        dst = os.path.join(srcDir, dstName)
    else: # use provided dstdir
        dst = os.path.join(dstDir, dstName)
    cmd = 'flac -d -o %s %s ' % (dst, src)
    os.system(cmd)
    return dst
Exemplo n.º 13
0
def soxFade(src, dst=None, timeIn=.01, timeOut=.01):
    # add a fade in and fade out to sound file
    # need total time 
    # this is destructive if dst id none
    timeTotal = fileDur(src)
    if dst == None: # replace original
        nameStub, ext = osTools.extSplit(src)
        dst = '%s-temp%s' % (nameStub, ext)
    #print 'in, out, total:', timeIn, timeOut, timeTotal
    # t is a linear slope
    cmd = 'sox %s %s fade t %s %s %s' % (src, dst, timeIn, timeTotal, timeOut)
    os.system(cmd)
    if dst == '%s-temp%s' % (nameStub, ext):
        osTools.mv(dst, src)
        #osTools.rm(dst)
    return src
Exemplo n.º 14
0
def decodeFlac(src, dstDir=None, dstName=None):
    """To decode:
  flac -d [INPUTFILE [...]] """
    srcDir, srcName = os.path.split(src)
    srcName, ext = osTools.extSplit(srcName)
    
    # optional dstName will be used instead of the srcName mod if provided
    if dstName == None:
        dstName = srcName + '.aif'
    if dstDir == None or not os.path.isdir(dstDir): #place in same dir
        dst = os.path.join(srcDir, dstName)
    else: # use provided dstdir
        dst = os.path.join(dstDir, dstName)
    cmd = 'flac -d -o %s %s ' % (dst, src)
    os.system(cmd)
    return dst
Exemplo n.º 15
0
def soxSplit(src):
    # this does not work for some reason

    #dst = src.replace(srcExt, dstExt)
    dir, name = os.path.split(src)
    nameStub, ext = osTools.extSplit(src)
    ext = '.aif'
    dstLeft = os.path.join(dir, nameStub + '.L' + ext)
    dstRight = os.path.join(dir, nameStub + '.R' + ext)

    # get left
    cmd = 'sox %s -c 1 %s avg -l' % (src, dstLeft)
    os.system(cmd)
    # get right
    cmd = 'sox %s -c 1 %s avg -r' % (src, dstRight)
    os.system(cmd)

    return dstLeft, dstRight
Exemplo n.º 16
0
def soxSplit(src):
    # this does not work for some reason

    #dst = src.replace(srcExt, dstExt)
    dir, name = os.path.split(src)
    nameStub, ext = osTools.extSplit(src)
    ext = '.aif'
    dstLeft = os.path.join(dir, nameStub + '.L' + ext)
    dstRight = os.path.join(dir, nameStub + '.R' + ext)

    # get left
    cmd = 'sox %s -c 1 %s avg -l' % (src, dstLeft)
    os.system(cmd)
    # get right
    cmd = 'sox %s -c 1 %s avg -r' % (src, dstRight)
    os.system(cmd)

    return dstLeft, dstRight
Exemplo n.º 17
0
def encodeOgg(src, dstDir=None, br=128, title='', 
                         artist='', album='', year=''):
    """ encode using oggenc
    -b   # bitrate,  can use -q 0-10 instead
    -o   # output filename
    -d   # date
    -a   # artist
    -t   # title
    -l   # album"""
    srcDir, srcName = os.path.split(src)
    srcName, ext = osTools.extSplit(srcName)
    dstName = srcName + '.ogg'
    if dstDir == None or not os.path.isdir(dstDir): #place in same dir
        dst = os.path.join(srcDir, dstName)
    else: # use provided dstdir
        dst = os.path.join(dstDir, dstName)
    
    tagStr = '-t "%s" -a "%s" -l "%s" -d %s ' % (title, artist, album, year)
    cmd = 'oggenc -w -b %s %s -o "%s" %s' % (br, tagStr, dst, src)
    os.system(cmd)
    return dst
Exemplo n.º 18
0
def encodeOgg(src, dstDir=None, br=128, title='', 
                         artist='', album='', year=''):
    """ encode using oggenc
    -b   # bitrate,  can use -q 0-10 instead
    -o   # output filename
    -d   # date
    -a   # artist
    -t   # title
    -l   # album"""
    srcDir, srcName = os.path.split(src)
    srcName, ext = osTools.extSplit(srcName)
    dstName = srcName + '.ogg'
    if dstDir == None or not os.path.isdir(dstDir): #place in same dir
        dst = os.path.join(srcDir, dstName)
    else: # use provided dstdir
        dst = os.path.join(dstDir, dstName)
    
    tagStr = '-t "%s" -a "%s" -l "%s" -d %s ' % (title, artist, album, year)
    cmd = 'oggenc -w -b %s %s -o "%s" %s' % (br, tagStr, dst, src)
    os.system(cmd)
    return dst