Beispiel #1
0
def runRecordGame(pipeline, game):
  try:
    freq = float(game['freq'])

    if game['band'] == 'am':
      freq = freq / 1000

    # Configure the shark (set station, turn fin red to indicate recording)
    execute('fm -q %.2f' % (freq))

    # Record the game
    print 'Recording ...', game
    execute(pipeline)
    print 'Recording complete.'
  except ExecuteError, err:
    print err
Beispiel #2
0
def runRecordGame(pipeline, game):
    try:
        freq = float(game['freq'])

        if game['band'] == 'am':
            freq = freq / 1000

        # Configure the shark (set station, turn fin red to indicate recording)
        execute('fm -q %.2f' % (freq))

        # Record the game
        print 'Recording ...', game
        execute(pipeline)
        print 'Recording complete.'
    except ExecuteError, err:
        print err
Beispiel #3
0
def verifAddrs(finName):
    fin = fins[finName]
    audioAddr = fin.audioAddr
    ctrlAddr = fin.ctrlAddr

    print "Using %s fin (audioAddr='%s', ctrlAddr='%s').\n" % (
        finName, fin.audioAddr, fin.ctrlAddr
    )
    print fill(dedent("""\
        This fin is about to be tested. This will reset the station on both fins.
        Do not do this if you are already recording a program on the other fin.
        You have 10 seconds to kill me to avoid changing the station.
    """))
    for i in range(9, -1, -1):
        sleep(1)
        print i
    sleep(1)

    print fill(dedent("""\
        This test sets both fins to KFOG (97.7 FM), a music station. It then
        sets the fin that is to be used to KNBR (680 AM), a sports talk station
        and then to KQED (88.5 FM), which is NPR. Each has its own distinct
        sound that should be distinguishable.  You should hear 10 seconds of
        sports talk and then 10 seconds of NPR. If you do not, then there are
        errors in the addresses and you need to fix fins.py.
    """))

    try:
        for audioAddr, ctrlAddr in product(audioAddrs, ctrlAddrs):
            for addr in ctrlAddrs:
                execute('sharkctrl -fm 97.7 %s' % addr)

        audioAddr = fin.audioAddr
        ctrlAddr = fin.ctrlAddr
        print "ctrl addr:", ctrlAddr
        print "audio addr:", audioAddr
        print "station: KNBR 680 AM"
        execute('sharkctrl -am 680 %s' % ctrlAddr)
        execute('sharkctrl -blue 0 %s' % ctrlAddr)
        execute('sharkctrl -red 1 %s' % ctrlAddr)
        execute(pipeline % audioAddr)
        print "station: KQED 88.5 FM"
        execute('sharkctrl -fm 88.5 %s' % ctrlAddr)
        execute('sharkctrl -blue 63 %s' % ctrlAddr)
        execute('sharkctrl -red 1 %s' % ctrlAddr)
        execute(pipeline % audioAddr)
        execute('sharkctrl -red 0 %s' % ctrlAddr)
        execute('sharkctrl -blue 63 %s' % ctrlAddr)
    except ExecuteError, err:
        exit(err.text)
Beispiel #4
0
        print "station: KNBR 680 AM"
        execute('sharkctrl -am 680 %s' % ctrlAddr)
        execute('sharkctrl -blue 0 %s' % ctrlAddr)
        execute('sharkctrl -red 1 %s' % ctrlAddr)
        execute(pipeline % audioAddr)
        print "station: KQED 88.5 FM"
        execute('sharkctrl -fm 88.5 %s' % ctrlAddr)
        execute('sharkctrl -blue 63 %s' % ctrlAddr)
        execute('sharkctrl -red 1 %s' % ctrlAddr)
        execute(pipeline % audioAddr)
        execute('sharkctrl -red 0 %s' % ctrlAddr)
        execute('sharkctrl -blue 63 %s' % ctrlAddr)
    except ExecuteError, err:
        exit(err.text)

if __name__ == "__main__":
    try:
        print "Football Fin"
        print "############"
        verifAddrs('football')
        print
        print "Baseball Fin"
        print "############"
        verifAddrs('baseball')
    except KeyboardInterrupt:
        execute('sharkctrl -red 0 %s' % ctrlAddr)
        execute('sharkctrl -blue 63 %s' % ctrlAddr)
        print "Killed at user request."
    except ExecuteError, err:
        exit(err.text)
Beispiel #5
0
        recorder=recorder, encoder=encoder
    )

    # assure destination directory exists
    mkdir(expandPath(AudioDirectory))

    # create a symbolic link to the latest game
    remove(latest)
    try:
        os.symlink(filename, latest)
    except (IOError, OSError), err:
        sys.exit("%s: %s." % (err.filename, err.strerror))

    try:
        # Configure the shark (set station, turn fin red to indicate recording)
        execute('sharkctrl %s %s' % (Station, SharkCtrlAddr))
        execute('sharkctrl -blue 0 %s' % SharkCtrlAddr)
        execute('sharkctrl -red 1 %s' % SharkCtrlAddr)

        # Record the game
        print 'Recording {desc} ({date}).'.format(**game)
        execute(pipeline)
        print 'Recording complete.'

        # Turn the fin back to blue to indicate not recording
        execute('sharkctrl -red 0 %s' % SharkCtrlAddr)
        execute('sharkctrl -blue 63 %s' % SharkCtrlAddr)
    except ExecuteError, err:
        sys.exit(err.text)
    announceNextGame(nextGame)
Beispiel #6
0
    END:VEVENT
"""
)
IcsFooter = dedent(
    """\
    END:VCALENDAR
"""
)

IcsFilename = "test.ics"
Duration = 1  # minutes (must be integer)
Repetitions = 2

now = datetime.utcnow()
starts = []
for offset in range(Repetitions):
    startTime = now + timedelta(0, 60 * Duration * (2 * offset + 1))
    # starts += [startTime.astimezone(tz.timezone('UTC'))]
    starts += [startTime]
with open(IcsFilename, "w") as icsFile:
    icsFile.write(IcsHeader)
    for start in starts:
        icsFile.write(IcsBody.format(time=start.strftime("%Y%m%dT%H%M%SZ"), game="test%s" % start.strftime("%M")))
    icsFile.write(IcsFooter)
try:
    execute("./49ersd.py --duration {} {}".format(Duration / 60, IcsFilename))
except ExecuteError, err:
    sys.exit(err.text)
except KeyboardInterrupt:
    exit("Killed by user")
Beispiel #7
0
def record(path, station, nextGame, Encoder):
    filename = os.path.join(
        path,
        nextGame.startDateTime.strftime("%m-%d") + "." + Encoder)

    # build the commands
    recorder = ' '.join([
        'arecord'  # audio recorder
        ,
        '-q'  # quiet
        ,
        '-d {duration}'  # recording time
        ,
        '--max-file-time {duration}'  # recording time before switching files (must be >= recording time)
        ,
        '-c 2'  # input stream is 2 channels
        ,
        '-f S16'  # input stream is 16 bit signed
        ,
        '-r 44100'  # rate of input stream is 44.1kHz
        ,
        '-D {device}'  # audio generator
        ,
        '-t raw'  # output format is raw (don't use .wav, it cuts out after 3 hours and 22 minutes because of a size limit on .wav files)
    ]).format(duration=RecordingDurationSec, device=SharkAudioAddr)

    if Encoder == 'ogg':
        encoder = ' '.join([
            'oggenc'  # Ogg encoder
            ,
            '-Q'  # quiet
            ,
            '-r'  # input format is raw
            ,
            '--resample 8000'  # sample rate (8000 and 11025 are suitable choices for AM radio)
            ,
            '--downmix'  # convert from stereo to mono
            ,
            '-q 0'  # quality level (range is -1 to 10 with 10 being highest)
            ,
            '--ignorelength'  # Allow input stream to exceed 4GB
            ,
            '-o "{filename}"'  # output file name
            ,
            '--title "{title} ({date})"'  # title
            ,
            '--album "{title}"'  # album
            ,
            '--artist "{artist}"'  # artist
            ,
            '--date "{date}"'  # date
            ,
            '-'  # read from standard input
        ]).format(filename=filename,
                  title=nextGame.description,
                  artist=nextGame.station,
                  date=nextGame.startDateTime.__repr__())
    elif Encoder == 'mp3':
        # DP- turned off old settings moved to 32kbps average; sounds much better
        encoder = ' '.join([
            'lame',
            '--quiet'  # quiet
            ,
            '-r'  # raw format input
            #, '--resample 8'          # resample to rate
            #, '-V3'                   # ???
            #, '--vbr-new'             # ???
            #, '-q0'                   # quality level
            #, '-B16'                  # maximum bit rate
            #, '--lowpass 15.4'        # apply lowpass filter
            #, '--athaa-sensitivity 1' # ???
            ,
            '--preset 32'  # average bitrate of 32kbps
            ,
            '--tt "{title}"'  # title
            ,
            '--ta "{artist}"'  # artist
            ,
            '-'  # read from standard input
            ,
            '{filename}'  # write to filename
        ]).format(filename=filename,
                  title=nextGame.description,
                  artist=nextGame.station,
                  date=nextGame.startDateTime.__repr__())
    elif Encoder == 'spx':
        # This generates files that sound a little better than the ogg files but
        # are much larger (odd because it is based on ogg and it tailored for
        # the spoken word, perhaps it is because I cannot get the -vbr option to
        # work). I am using the wideband option because it sounded
        # better and took less space than the narrowband option.
        encoder = ' '.join([
            'speexenc',
            '-w'  # wideband
            #, '--16bit'              # 16 bit raw input stream
            #, '--le'                 # little endian input stream
            #, '--stereo'             # stereo input stream
            ,
            '--title "{title}"'  # title
            ,
            '--author "{artist}"'  # artist
            ,
            '-'  # read from standard input
            ,
            '{filename}'  # write to filename
        ]).format(filename=filename,
                  title=nextGame.description,
                  artist=nextGame.station,
                  date=nextGame.startDateTime.__repr__())
    else:
        raise AssertionError, "%s: Unknown encoder" % encoder

    pipeline = '{recorder} | {encoder}'.format(recorder=recorder,
                                               encoder=encoder)

    try:
        # Configure the shark (set station, turn fin red to indicate recording)
        execute('%s %s %s' % (SHARK_EXE, station, SharkCtrlAddr))
        execute('%s -blue 0 %s' % (SHARK_EXE, SharkCtrlAddr))
        execute('%s -red 1 %s' % (SHARK_EXE, SharkCtrlAddr))

        # Record the game
        print 'Recording ...', nextGame
        execute(pipeline)
        print 'Recording complete.'

        # Turn the fin back to blue to indicate not recording
        execute('%s -red 0 %s' % (SHARK_EXE, SharkCtrlAddr))
        execute('%s -blue 63 %s' % (SHARK_EXE, SharkCtrlAddr))

        if os.path.exists("./postRec.sh"):
            os.system("/bin/sh " + "./postRec.sh")

    except ExecuteError, err:
        print err
        sys.exit()
Beispiel #8
0
    'FALSE',
    'TRUE',
    '04/06/12',
    '03:10 PM',
    '06:10 PM',
    'FREE',
    'BUSY'
]) + '\n'
CsvFilename = 'test.csv'
Duration = 1 # minutes (must be integer)
Repetitions = 2

now = datetime.now()
starts = []
for offset in range(Repetitions):
    starts += [now + timedelta(0, 60*Duration*(2*offset + 1))]
with open(CsvFilename, 'w') as csvFile:
    csvFile.write(CsvHeader)
    for start in starts:
        csvFile.write(
            CsvBody.format(
                date=start.strftime('%m/%d/%y'),
                time=start.strftime('%I:%M %p'),
                game="test%s" % start.strftime('%M')))
try:
    execute('./giantsd.py --duration {} {}'.format(Duration/60, CsvFilename))
except ExecuteError, err:
    sys.exit(err.text)
except KeyboardInterrupt :
    exit('Killed by user')