Esempio n. 1
0
def readTracks():
    cd.init()
    if cd.getCount() == 0:
        print 'There is no cdrom found. Bailing out...'
        return 0

    c = cd.CD(0)
    props = c.getProperties()
    if props['type'] != 'AudioCD':
        print 'Media in %s has type %s, not AudioCD. Cannot read audio data.' % (
            c.getName(), props['type'])
        return 0

    t = time.time()
    bytes = 0
    for i in xrange(len(props['titles'])):
        print 'Reading %d track' % (i + 1)
        tr = c.open(props['titles'][i])
        s = ' '
        while len(s):
            s = tr.read(CHUNK_SIZE)
            bytes += len(s)

    print '%d bytes read in %.2f secs ( %d bytes/sec )' % (bytes, time.time() -
                                                           t, bytes /
                                                           (time.time() - t))
Esempio n. 2
0
def readTrack( track, offset, bytes ):
  cd.init()
  if cd.getCount()== 0:
    print 'There is no cdrom found. Bailing out...'
    return 0
  
  c= cd.CD(0)
  props= c.getProperties()
  if props[ 'type' ]!= 'AudioCD':
    print 'Media in %s has type %s, not AudioCD. Cannot read audio data.' % ( c.getName(), props[ 'type' ] )
    return 0
  
  tr0= c.open( props[ 'titles' ][ track- 1 ] )
  tr0.seek( offset, cd.SEEK_SET )
  f= wave.open( props[ 'titles' ][ track- 1 ]+ '.wav', 'wb' )
  f.setparams( (2, 2, 44100, 0, 'NONE','') )
  s= ' '
  while len( s ) and bytes:
    if bytes> CHUNK_SIZE:
      s= tr0.read( CHUNK_SIZE )
    else:
      s= tr0.read( bytes )
    
    f.writeframes( s )
    bytes-= len( s )
Esempio n. 3
0
def readTrack(track, offset, bytes):
    cd.init()
    if cd.getCount() == 0:
        print 'There is no cdrom found. Bailing out...'
        return 0

    c = cd.CD(0)
    props = c.getProperties()
    if props['type'] != 'AudioCD':
        print 'Media in %s has type %s, not AudioCD. Cannot read audio data.' % (
            c.getName(), props['type'])
        return 0

    tr0 = c.open(props['titles'][track - 1]['name'])
    tr0.seek(offset, cd.SEEK_SET)
    return tr0.read(bytes)
Esempio n. 4
0
def playTrack( track ):
  cd.init()
  if cd.getCount()== 0:
    print 'There is no cdrom found. Bailing out...'
    return 0
  
  c= cd.CD(0)
  props= c.getProperties()
  if props[ 'type' ]!= 'AudioCD':
    print 'Media in %s has type %s, not AudioCD. Cannot read audio data.' % ( c.getName(), props[ 'type' ] )
    return 0
  
  tr0= c.open( props[ 'titles' ][ track- 1 ] )
  snd= sound.Output( 44100, 2, sound.AFMT_S16_LE )
  s= ' '
  while len( s ):
    s= tr0.read( CHUNK_SIZE )
    snd.play( s )
  
  while snd.isPlaying():
    time.sleep( .01 )
Esempio n. 5
0
def playTrack(track):
    cd.init()
    if cd.getCount() == 0:
        print 'There is no cdrom found. Bailing out...'
        return 0

    c = cd.CD(0)
    props = c.getProperties()
    if props['type'] != 'AudioCD':
        print 'Media in %s has type %s, not AudioCD. Cannot read audio data.' % (
            c.getName(), props['type'])
        return 0

    tr0 = c.open(props['titles'][track - 1])
    snd = sound.Output(44100, 2, sound.AFMT_S16_LE)
    s = ' '
    while len(s):
        s = tr0.read(CHUNK_SIZE)
        snd.play(s)

    while snd.isPlaying():
        time.sleep(.01)
Esempio n. 6
0
def readTracks():
  cd.init()
  if cd.getCount()== 0:
    print 'There is no cdrom found. Bailing out...'
    return 0
  
  c= cd.CD(0)
  props= c.getProperties()
  if props[ 'type' ]!= 'AudioCD':
    print 'Media in %s has type %s, not AudioCD. Cannot read audio data.' % ( c.getName(), props[ 'type' ] )
    return 0
  
  t= time.time()
  bytes= 0
  for i in xrange( len( props[ 'titles' ] ) ):
    print 'Reading %d track' % ( i+ 1 )
    tr= c.open( props[ 'titles' ][ i ] )
    s= ' '
    while len( s ):
      s= tr.read( CHUNK_SIZE )
      bytes+= len( s )
  
  print '%d bytes read in %.2f secs ( %d bytes/sec )' % ( bytes, time.time()- t, bytes / ( time.time()- t ) )