Ejemplo n.º 1
0
def doIdleSpeech():
    while True:
        if DARK_SCHEDULE.is_now() and phoneState == PHONE_STATE_IDLE:
            ba.channels[ba.CHAN_SPKR_A].unmute()
            if not ba.busy(ba.CHAN_SPKR_A):
                ba.play_loop(ba.CHAN_SPKR_A,
                             ambStatic,
                             fade_ms=DARK_STATIC_FADE_MS,
                             token=DARK_SFX_TOKEN)

        # Calculate delay before next cluster and wait
        delay = random.randint(MIN_PHRASE_DELAY, MAX_PHRASE_DELAY + 1)
        time.sleep(delay)

        # Check if it's the right time to talk
        dt = datetime.now()

        if DARK_SCHEDULE.is_now() and phoneState == PHONE_STATE_IDLE:
            # Determine phrase cluster size
            clusterSize = random.choice(CLUSTER_SIZES)
            for x in range(clusterSize):
                # Wait for playing to finish
                ba.wait(ba.CHAN_SPKR_B)
                # Choose random phrase and play it
                phrase = random.choice(phrases)
                ba.play(ba.CHAN_SPKR_B,
                        phrase,
                        volume=DARK_VOICE_VOLUME,
                        token=DARK_SFX_TOKEN)
                # Calculate delay before next phrase in cluster and wait
                clusterDelay = random.uniform(PHRASE_CLUSTER_DELAY_MIN,
                                              PHRASE_CLUSTER_DELAY_MAX)
                time.sleep(clusterDelay)
        elif phoneState == PHONE_STATE_IDLE:
            ba.stop(ba.CHAN_SPKR_A, fade_ms=DARK_STATIC_FADE_MS)
Ejemplo n.º 2
0
def setPhoneState(state):
    global phoneState, dialedNumber

    if phoneState == state:
        return

    if state == PHONE_STATE_IDLE:
        ba.stop()
        dialedNumber = ""
        digitEvent.set()
        digitEvent.clear()
    elif state == PHONE_STATE_DIAL:
        ba.play_loop(ba.CHAN_TELEPHONY, dialTone)
        ba.stopsfx()
        ba.stop_token(DARK_SFX_TOKEN)
    elif state == PHONE_STATE_DIAL_DELAY:
        ba.stop(ba.CHAN_TELEPHONY)
    elif state == PHONE_STATE_OFF_HOOK_MSG:
        ba.stop(ba.CHAN_TELEPHONY)
    elif state == PHONE_STATE_OFF_HOOK:
        ba.play_loop(ba.CHAN_TELEPHONY, offHookTone)
    elif state == PHONE_STATE_RING:
        ba.play_loop(ba.CHAN_TELEPHONY, ringTone)
    elif state == PHONE_STATE_BUSY:
        ba.stop()
        ba.play_loop(ba.CHAN_TELEPHONY, busyTone)
    elif state == PHONE_STATE_CALL:
        ba.stop(ba.CHAN_TELEPHONY)
    phoneState = state
Ejemplo n.º 3
0
def call(bwwp, num, answer, hangup):
    global connected

    menuStatus = MENU_STATUS_NONE

    def menu_volume():
        print "OPERATOR: Volume menu"
        ba.say(phrases['volume'])
        digit = -1
        while True:
            digit = bwwp.read_digit()
            if not connected:
                return MENU_STATUS_NONE
            if digit == 0:
                ba.say(phrases['back'])
                print "OPERATOR: Back"
                break
            vol = float(digit) / 9.0
            print "OPERATOR: Volume set to %.2f" % (vol)
            ba.set_volume(vol)
        return MENU_STATUS_NONE

    def menu_power_options():
        print "OPERATOR: Power Options menu"
        ba.say(phrases['power_options'])
        digit = -1
        while True:
            digit = bwwp.read_digit()
            if not connected:
                return MENU_STATUS_NONE
            if digit == 1:
                ba.say_wait(phrases['ok'])

                def do_reboot():
                    time.sleep(3)
                    subprocess.Popen(['sudo', 'reboot'])

                threading.Thread(target=do_reboot).start()
                endFlag = True
                return MENU_STATUS_HANGUP
            elif digit == 2:
                ba.say_wait(phrases['ok'])

                def do_halt():
                    time.sleep(3)
                    subprocess.Popen(['sudo', 'halt'])

                threading.Thread(target=do_halt).start()
                endFlag = True
                return MENU_STATUS_HANGUP
            elif digit == 0:
                ba.say(phrases['back'])
                print "OPERATOR: Back"
                break
        return MENU_STATUS_NONE

    time.sleep(random.uniform(3.0, 8.0))

    if not answer():
        return

    connected = True

    # Start the gross sounds
    ba.play_loop(ba.CHAN_SFX_A, breathSound, fade_ms=10000)
    ba.play(ba.CHAN_SFX_B, random.choice(bwwp.pickupSounds))
    ba.play_loop(ba.CHAN_SFX_C, bgSoundA)
    ba.play_loop(ba.CHAN_SFX_D, bgSoundB)

    # Say "Operator."
    time.sleep(random.uniform(0.3, 1.5))
    ba.say(phrases['operator'])

    digit = -1
    while connected and menuStatus == MENU_STATUS_NONE:
        digit = bwwp.read_digit()
        if digit == 1:
            menuStatus = menu_volume()
        elif digit == 2:
            menuStatus = menu_power_options()
        elif digit == 0:
            break

    print "OPERATOR: Exiting"

    if not connected:
        return

    if menuStatus != MENU_STATUS_HANGUP:
        ba.say_wait(phrases['bye'])
        time.sleep(0.25)

    ba.play(ba.CHAN_SFX_A, random.choice(bwwp.hangupSounds))
    ba.wait(ba.CHAN_SFX_A)

    hangup()
Ejemplo n.º 4
0
def call(bwwp, num, answer, hangup):
    global connected

    endCallEvent.clear()
    menuStatus = MENU_STATUS_NONE
    dt = datetime.now()
    dark = DARK_SCHEDULE.is_now()
    phrases = phrasesB if dark else phrasesA

    def menu_volume():
        print "OPERATOR: Volume menu"
        ba.say(phrases['volume'])
        digit = -1
        while True:
            digit = bwwp.read_digit()
            if not connected:
                return MENU_STATUS_NONE
            if digit == '0':
                ba.say(phrases['back'])
                print "OPERATOR: Back"
                break
            vol = float(digit) / 9.0 if digit in '1234567890' else 1.0
            print "OPERATOR: Volume set to %.2f" % (vol)
            ba.set_volume(vol)
            ba.say(phrases['ok'])
        return MENU_STATUS_NONE

    def menu_power_options():
        print "OPERATOR: Power Options menu"
        ba.say(phrases['power_options'])
        digit = -1
        while True:
            digit = bwwp.read_digit()
            if not connected:
                return MENU_STATUS_NONE
            if digit == '1':
                ba.say_wait(phrases['ok'])

                def do_reboot():
                    time.sleep(3)
                    subprocess.Popen(['sudo', 'reboot'])

                threading.Thread(target=do_reboot).start()
                endFlag = True
                return MENU_STATUS_HANGUP
            elif digit == '2':
                ba.say_wait(phrases['ok'])

                def do_halt():
                    time.sleep(3)
                    subprocess.Popen(['sudo', 'halt'])

                threading.Thread(target=do_halt).start()
                endFlag = True
                return MENU_STATUS_HANGUP
            elif digit == '0':
                ba.say(phrases['back'])
                print "OPERATOR: Back"
                break
        return MENU_STATUS_NONE

    def menu_ring_test():
        print "OPERATOR: Ring Test"
        ba.say_wait(phrases['ring_test'])
        bwwp.set_ring_state(True)
        digit = -1
        while True:
            digit = bwwp.read_digit()
            if not connected:
                break
            if digit == '0':
                ba.say(phrases['back'])
                print "OPERATOR: Back"
                break

        bwwp.set_ring_state(False)
        return MENU_STATUS_NONE

    def sfx_func(ch):
        miscSounds = darkMiscSounds if dark else lightMiscSounds
        while connected:
            interval = random.uniform(
                *(DARK_SFX_INTERVAL if dark else LIGHT_SFX_INTERVAL))
            if endCallEvent.wait(timeout=interval):
                return
            ba.wait(ch)
            ba.play(ch,
                    random.choice(miscSounds),
                    volume_mul=random.uniform(0.5, 1.0))

    sfxThreads = []
    sfxLayerCount = DARK_SOUND_LAYERS if dark else LIGHT_SOUND_LAYERS
    for i in range(sfxLayerCount):
        sfxThread = threading.Thread(target=sfx_func,
                                     args=(i + ba.CHAN_SFX_E, ))
        sfxThread.daemon = True
        sfxThreads.append(sfxThread)

    try:
        time.sleep(
            random.uniform(
                *(DARK_PICKUP_DELAY if dark else LIGHT_PICKUP_DELAY)))

        if not answer():
            return

        connected = True

        # Play pickup sound
        ba.play(ba.CHAN_SFX_A, random.choice(bwwp.pickupSounds))

        # Start background ambience
        if dark:
            ba.play_loop(ba.CHAN_SFX_B, breathSound, fade_ms=10000)
            ba.play_loop(ba.CHAN_SFX_C, amb['drip'])
            ba.play_loop(ba.CHAN_SFX_D, amb['flies'])
        else:
            ba.play_loop(ba.CHAN_SFX_B, amb['office'])

        # Start background SFX threads
        for sfxThread in sfxThreads:
            sfxThread.start()

        # Say "Operator."
        time.sleep(random.uniform(0.3, 1.5))
        ba.say(phrases['operator'])

        digit = -1
        while connected and menuStatus == MENU_STATUS_NONE:
            digit = bwwp.read_digit()
            if digit == '1':
                menuStatus = menu_volume()
            elif digit == '2':
                menuStatus = menu_power_options()
            elif digit == '3':
                menuStatus = menu_ring_test()
            elif digit == '0':
                break

        print "OPERATOR: Exiting"

        if not connected:
            return

        if menuStatus == MENU_STATUS_BYE:
            ba.say_wait(phrases['bye'])
            time.sleep(0.25)

        ba.play(ba.CHAN_SFX_A, random.choice(bwwp.hangupSounds))
        ba.wait(ba.CHAN_SFX_A)

        hangup()
    finally:
        endCallEvent.set()