omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    Sounds & Fonts

    Pythonista
    14
    30
    24160
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Sebastian
      Sebastian last edited by

      This worked for me:

      I downloaded a mp3-file <b><I>my_sound.mp3</I></b> to the same directory as the script. Changed the file extension to <i>my_sound<b>.caf</b></i> and then called it like this: <PRE>sound.play_effect(os.getcwd()+'/my_sound')</PRE>
      Let me know if it works for you guys.

      1 Reply Last reply Reply Quote 0
      • eliskan175
        eliskan175 last edited by

        Hey that worked wonderfully! Sorry it took so long to respond, but I have to say this solution is crucial for playing sounds.

        Here's a fully working example, which downloads an mp3 then plays it indefinitely (to end the script, press stop then wait for the sleep to timeout): https://gist.github.com/adc2874aa09640237f6f. What this script does is creates a Sounds folder (if one doesn't already exist) then downloads the file (if the file doesn't already exist). If the file and folder already exists, then it doesn't need to be online and will simply access the resource.

        Just change the file and URL names to fit your mp3 file and you can hear it played.

        Thank you Sebastion for this solution!!! I will DEFINITELY be using this

        1 Reply Last reply Reply Quote 0
        • Sebastian
          Sebastian last edited by

          I'm glad it's working :)

          1 Reply Last reply Reply Quote 0
          • Cubbarooney104
            Cubbarooney104 last edited by

            Yay! That solved the problem of not able to add sounds :)

            Now I need to make a space game for the sound Eliskan just downloaded... Hmmmm...

            Cubbarooney

            1 Reply Last reply Reply Quote 0
            • ccc
              ccc last edited by

              Is there a programmatic way to get a list of all fonts currently available to Pythonista?

              1 Reply Last reply Reply Quote 0
              • omz
                omz last edited by

                @ccc No, but <a href="http://iosfonts.com">iosfonts.com</a> has a handy reference.

                1 Reply Last reply Reply Quote 0
                • Phuket2
                  Phuket2 last edited by

                  This is an old post from Aug, 2013. But I was also looking to see if could programmatically get a list of the device fonts.
                  Does anyone know if any inroads have been made on this subject either by omz or a community member?

                  I looked at iosfonts.com, looks nice and up to date. Whilst the html code is script generated, sure there is still away to capture the rendered html and write a file to disk. But I realise this is not a nice way to get information without the website owners permission. I wouldn't do it that way, I am not looking for a solution just for myself, but all of the community here.

                  If there is no solution as yet, I think it would be nice if one of us spoke to the owners of this site or a similar site to get a supported interface for this community. If it's takes a donation to get it done, I am up for that.

                  BUT TO BE VERY CLEAR!!! I would never try and speak for the community here (pythonista) without express permission from omz. I am not trying to make a drama out of this issue. I just think some things are better solved for all of us at once rather than all of us going off in our own directions. I think this is a part of a platforms eveloution.

                  I don't always have the best ideas, but my heart is in the right place. Even though I have been out of the loop for many years, still many basic principles remain the same.

                  So if it has been solved great, love to hear the answer. Regardless, I wanted to bring up the point of trying to solve problems for all of us instead of individuals. Not to say that does not happen here. There is a huge amount of collaboration here. I really love it. The reasons for my comments. Anything that can be done to further pythonista and the community, I am in for.

                  1 Reply Last reply Reply Quote 0
                  • omz
                    omz last edited by

                    It would be pretty easy to do this in 1.6, using objc_util, but I think you're still on 1.5, right?

                    Edit: It would look something like this:

                    from objc_util import *
                    
                    UIFont = ObjCClass('UIFont')
                    all_fonts = []
                    families = UIFont.familyNames()
                    for family in families:
                      names = UIFont.fontNamesForFamilyName_(family)
                      all_fonts += names
                    
                    1 Reply Last reply Reply Quote 0
                    • cook
                      cook last edited by

                      Also- that website project is here:
                      https://github.com/mcritz/iosfonts?files=1

                      Read the license. Looks like you could use it with reference.
                      Json file in the data folder.

                      1 Reply Last reply Reply Quote 0
                      • Phuket2
                        Phuket2 last edited by

                        Yes omz , still 1.5. I can see I have to be a little bit careful about my comments as it seems a lot will be possible with 1.6 that's not possible in 1.5. I will roll my own solution for now. Good learning exp. for me. If I knew 1.5 back the front, I would be begging to get 1.6, but I have a long way to go :) but ok thanks, it answers my question.

                        1 Reply Last reply Reply Quote 0
                        • omz
                          omz last edited by

                          I don't really think you can copyright a list of fonts that is most likely generated automatically, but giving credit is always nice of course.

                          The benefit of generating the list dynamically on the device are

                          a) It would include custom fonts that are bundled with Pythonista.

                          b) It would update automatically when new fonts are added in the OS.

                          c) You don't need an internet connection.

                          ...but anyway, right now it's only possible in the 1.6 beta, so if you're on 1.5, scraping iosfonts.com is probably a good option.

                          1 Reply Last reply Reply Quote 0
                          • Phuket2
                            Phuket2 last edited by

                            @omz, I agree with all your points. I think I am getting a little used to its not possible on iOS. But, I don't get stressed about it, I have time. I was very inflexible when I was younger, but now I am fairly laid back. Well really laid back :)

                            Actually, the repo that @cook points to, has a JSON file from the author of the iosfonts.com website. So that was nice of him. I have no commercial interest in any data, trying to write a few apps for some good friends.

                            @cook, thanks for the repo link. I have got the JSON file. Now will try to understand it programmatically :)

                            1 Reply Last reply Reply Quote 0
                            • reefboy1
                              reefboy1 last edited by

                              I'm pretty sure with the beta (which you can through via TestFlight by Apple https://appsto.re/us/W4wM1.i)
                              You are able to record audio. I remember a while back I asked a similar question, if you search "Audio" and look for a question by Reefboy1, there should be some help there. Good luck!

                              1 Reply Last reply Reply Quote 0
                              • Webmaster4o
                                Webmaster4o last edited by Webmaster4o

                                One way to get a list of fonts might be to pull a long list of font names off somewhere and see which ones don't produce errors if you try to use them.

                                Something like:

                                # coding: utf-8
                                from PIL import ImageFont
                                
                                fonts = ["Helvetica", "Courier", "FontNameThatDoesNotExist", "Arial", "PoopingPenguins", "Inconsolata"]
                                
                                installed_fonts = []
                                for font in fonts:
                                	try:
                                		ImageFont.truetype(font, 10)
                                		installed_fonts.append(font)
                                	except:
                                		print "Font '"+font+"' not found."
                                
                                
                                print "\nThe installed fonts are:\n" + "\n".join(installed_fonts)
                                
                                1 Reply Last reply Reply Quote 0
                                • omz
                                  omz last edited by

                                  That won't work (console.set_font never throws an exception, it just ignores invalid fonts).

                                  1 Reply Last reply Reply Quote 0
                                  • Webmaster4o
                                    Webmaster4o last edited by

                                    Ah, thanks. What about PIL.ImageFont?

                                    1 Reply Last reply Reply Quote 0
                                    • omz
                                      omz last edited by

                                      I think that would work, yes.

                                      1 Reply Last reply Reply Quote 0
                                      • Webmaster4o
                                        Webmaster4o last edited by Webmaster4o

                                        Edited, but still haven't tested. Can someone test that code for me?

                                        1 Reply Last reply Reply Quote 0
                                        • ccc
                                          ccc last edited by ccc

                                          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: to except TypeError:. ;-)

                                          1 Reply Last reply Reply Quote 1
                                          • Webmaster4o
                                            Webmaster4o last edited by

                                            Right, @ccc, but I didn't know what kind of exception it would throw since I'm not somewhere I can test it.

                                            1 Reply Last reply Reply Quote 0
                                            • First post
                                              Last post
                                            Powered by NodeBB Forums | Contributors