Forum Archive

Quick Tip: Using iOS System Sound Effects

omz

Just a quick tip if you're bored with the standard sound effects that are included with Pythonista:

You can actually use a lot of standard iOS sound effects as well (e.g. the various text message sounds). Here's how:

import os
import sound
import time

for dirpath, dirnames, filenames in os.walk('/System/Library/Audio/UISounds'):
    for f in filenames:
        if f.endswith('.caf'):
            full_path = os.path.join(dirpath, f)
            sound.play_effect(full_path)
            time.sleep(1)

As of iOS 7.1, there are 99 of them. Have fun!

gregory.pease.280

Any hope for future support for playing music?

ccc

http://omz-forums.appspot.com/pythonista/post/6155976625356800 change the file extension from .mp3 to .caf... It would probably be a cool update to Pythonista if it played .mp3 files without requiring that you change the file extension to .caf.

pruppert222

Ha. Nice. It's just fun to play that script and hear them all.

kirorp

Here a list of some sounds with there names http://theiphonewiki.com/wiki//System/Library/Audio/UISounds

ccc

blue_box_dialer.py ;-)

# http://en.wikipedia.org/wiki/Blue_box
# http://en.wikipedia.org/wiki/Dual-tone_multi-frequency_signaling

# Change the phone number below and then hold your iOS device next
# to an off-the-hook phone and the DTMF tones will make the call.
#
# Phone companies have learned a lot since the days of phreaking so
# you should expect any calls made to appear on your monthly bill.

phone_number_to_dial = '0081787881218'  # '12345#,765#,*'

import os, sound, time

fmt = '/System/Library/Audio/UISounds/dtmf-{}.caf'

def dial_number(in_phone_number = phone_number_to_dial):
    def dial_digit(in_digit):
        if in_digit == ',':  # a comma is a 2 second pause
            time.sleep(2)
        else:
            sound.play_effect(fmt.format(in_digit))
            time.sleep(0.3)  # changes the dial speed

    print('Dialing: %s' % in_phone_number)
    in_phone_number = in_phone_number.replace('#', 'pound').replace('*', 'star')
    for digit in in_phone_number:
        dial_digit(digit)

dial_number(phone_number_to_dial)
omz

Haha, awesome!

TiffanyAlvarado

Our future people have changed music is now free for everyone