Sounds & Fonts
-
It seems to me that the only sounds that can be used are the ones that come with the app. Is this true? Or is there something I'm overlooking? Same thing with fonts, can new ones be added?
Just wondering,
Thanks,
Cubbarooney
-
Edited, but still haven't tested. Can someone test that code for me?
-
Yes. The code works as expected if you remove the quotes around "font" in the append() line.
Of course it is also best practice to change
except:
toexcept TypeError:
. ;-)
-
Right, @ccc, but I didn't know what kind of exception it would throw since I'm not somewhere I can test it.
-
I love that you can play sounds directly from their urls. Is there a way to simplify the script for this?
-
@jerovargas something like this?
import ui webview = ui.WebView() webview.frame = (0,0,600,100) url = 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/123941/Yodel_Sound_Effect.mp3' webview.load_url(url) webview.present('sheet')
-
What about using these apis... http://omz-software.com/pythonista/docs/ios/sound.html
-
@ccc He asked to play directly from url...
-
@jerovargas, here’s a more light-weight alternative, which does play the sound ”directly from the url”, but only after it has been fully downloaded. I tried to combine streaming with
play_effect
, but was unsuccessful.import tempfile import sound import requests def play(url): with tempfile.NamedTemporaryFile(suffix='.caf') as fp: r = requests.get(url) r.raise_for_status() fp.write(r.content) sound.play_effect(fp.name) play('https://s3-us-west-2.amazonaws.com/s.cdpn.io/123941/Yodel_Sound_Effect.mp3')
-
@jerovargas, ok, a version that streams a longer file instead of downloading it first.
import objc_util objc_util.load_framework('AVFoundation') AVPlayer = objc_util.ObjCClass('AVPlayer') def play(url): audio_player = AVPlayer.playerWithURL_(objc_util.nsurl(url)) audio_player.play() return audio_player player = play('https://file-examples.com/wp-content/uploads/2017/11/file_example_MP3_2MG.mp3') input('Press enter to stop') player.pause()