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.
downloading portions of github repos
-
I have taken suggestions from @jsbain and used mp3 files from
gleitz/midi-js-soundfonts
to add more realistic sounds to chordcalc. My questions is: can I do this programmatically so as not to inflate the existing repos, much like shellista does. -
I am assuming that you want the .mp3 files like in the
accordion-mp3
directory rather than the .js files likeaccordion-mp3.js
.import bs4, requests url = 'https://github.com/gleitz/midi-js-soundfonts/tree/master/FluidR3_GM' soup = bs4.BeautifulSoup(requests.get(url).text) hrefs = [x for x in soup.find_all('a', href=True) if x.text.endswith('-mp3')] print('{} midi-js-soundfonts were found.'.format(len(hrefs))) print('\n'.join(x.text for x in hrefs))
hrefs
is a list of links to 128 midi-js-soundfonts. -
As usual, asked before I thought. Came up with a similar solution, but thanks. This is more or less how I load images into my flashcard script (the
get_ASL_jpgs.py
script). But alas, no mandolin "font'. Off to my recording studio!!! -
A more complete solution:
https://github.com/cclauss/uncategorized_hacks/blob/master/get_midi_js_soundfonts.py
-
re: mando soundfont, a little googling reveals
http://soundfonts.homemusician.net/guitar_soundfonts/mandolin.htmlI haven't tried it, but https://github.com/mudcube/MIDI.js has a generator that lets you convert soundfonts to mp3.
-
I would take another direction and just enhance your existing "synthesizer" approach. Here is code demonstrating how to create a very realistic sounding guitar string from scratch. You could use an approach like this to actually generate your chords on the fly as a single playable WAV file that is thrown away after it is played.
# # A simple music synthesis using Karplus-Strong Algorithm # from random import random from array import array import wave import sound SampleRate=44100 notes=[391,440,489,521,586,660,734,782] duration=[16,4,16,4,64,16,4,8] nchannels,swdth,frame_rate,nframes=1,2,44100,44100 max_val=32767 def Generate(f,nsamples): N=SampleRate//f buf=[random()-0.5 for i in range(N)] samples=[] bufSize=len(buf) for i in range(nsamples): samples.append(buf[0]) avg=0.997*0.5*(buf[0]+buf[1]) buf.append(avg) buf.pop(0) tempbuf=[int(x*max_val) for x in samples] data=array('h',tempbuf).tostring() file.writeframes(data) file=wave.open('karplus_strong.wav','wb') file.setparams((nchannels,swdth,frame_rate,nframes,'NONE','nonecompressed')) for i in range(len(notes)): Generate(notes[i],44100//duration[i]) file.close() sound.play_effect('karplus_strong.wav')
-
All:
I have tried various solutions to downloading the mp3 files in a forked version on Gleitz's repo (uner my account). and while I can download an object it is not playable. Can somene try to download either this and tell me it it plays a sound. Here is a url
url = "https://github.com/gleitz/midi-js-soundfonts/tree/master/FluidR3_GM/pizzicato_strings-mp3/F5.mp3"
If clone the repo to my Mac and use iMazing to move the files to the iPad, if plays.
-
https://github.com/gleitz/midi-js-soundfonts/blob/master/FluidR3_GM/pizzicato_strings-mp3/F5.mp3?raw=true
From my more complete solution link above:
def get_mp3_from_filepath(filepath='acoustic_guitar_steel-mp3/A1.mp3'): fmt = '{}/{}?raw=true' url = fmt.format(base_url.replace('/tree/', '/blob/'), filepath) with open(filepath, 'wb') as out_file: out_file.write(requests.get(url).content)
tree --> blob
andraw=true
are key tricks to getting a playable mp3 file. -
Yep. or use the url:
url = "https://raw.githubusercontent.com/gleitz/midi-js-soundfonts/master/FluidR3_GM/acoustic_guitar_steel-mp3/A6.mp3"
Figured that one out about 2 seconds ago. Thanks