Close

Hacking AccessBrailleRAP with MuseScore

A project log for BrailleRAP DIY Braille embosser

An Open source Braille embosser in the spirit of RepRap

stephaneStephane 05/28/2023 at 15:120 Comments

Since we started the BrailleRAP project a few years ago, we eared some peoples asking about Braille music score. 

As we were focused on literacy transcription, we just put aside this feature, just noticing that Braille music score is just another standard in the Braille word.

I'm not a musician, but sometime i love to make some music hack with bio sensor, midi and software synth on Raspberry PI. As hacking around with musical open source software, i've discovered MuseScore (https://musescore.org/). MuseScore is a wonderful and impressive open source tool to edit and display music score, as well as handling many music file format.

Last night, looking for some python module for a customer, i just found music21 "a toolkit for computer-aided musicology" (http://web.mit.edu/music21/#) and this article by Young Choi about Braille and music21 (https://www.linkedin.com/pulse/convert-music-xml-braille-music21-young-choi/) with just a few lines of python to translate a musicxml file into Braille. Starting from Young Choi example, i just create a python venv and write a little script :

import music21
import sys

print (sys.argv)
c = music21.converter.parse (sys.argv[1])

c.show ('braille')
#c.show ('png')
bu = music21.braille.translate.objectToBraille (c, maxLineLength=28, showHeading=True)

data = bu.splitlines()
for l in data:
    print ("{0} |{1}|".format(len(l), l))

getting some musicxml around, i tried the script and get this

and this in the console :

33 |⠠⠉⠕⠍⠏⠕⠎⠑⠗⠒⠀⠠⠇⠥⠙⠺⠊⠛⠀⠧⠁⠝⠀⠠⠃⠑⠑⠞⠓⠕⠧⠑⠝|
26 |⠠⠍⠕⠧⠑⠍⠑⠝⠞⠀⠠⠝⠁⠍⠑⠒⠀⠎⠉⠕⠗⠑⠲⠭⠍⠇|
33 |⠠⠞⠊⠞⠇⠑⠒⠀⠠⠋⠈⠥⠗⠀⠠⠑⠇⠊⠎⠑⠀⠊⠝⠀⠠⠁⠀⠠⠍⠊⠝⠕⠗|
27 |⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠼⠉⠦⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀|
27 |⠀⠚⠀⠨⠜⠐⠀⠀⠀⠨⠯⠩⠑⠋⠐⠚⠡⠑⠙⠀⠐⠊⠍⠐⠙⠋⠊|
27 |⠀⠀⠀⠸⠜⠄⠄⠍⠀⠍⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠘⠮⠸⠯⠮⠍⠭|
23 |⠀⠉⠀⠨⠜⠐⠚⠍⠋⠩⠓⠚⠀⠀⠨⠙⠍⠐⠋⠨⠋⠩⠑|
23 |⠀⠀⠀⠸⠜⠘⠯⠸⠯⠩⠷⠍⠭⠀⠘⠮⠸⠯⠮⠍⠭⠀⠀|
23 |⠀⠑⠀⠨⠜⠨⠯⠩⠑⠋⠐⠚⠡⠑⠙⠀⠐⠊⠍⠐⠙⠋⠊|
23 |⠀⠀⠀⠸⠜⠄⠄⠍⠀⠀⠀⠀⠀⠀⠀⠀⠘⠮⠸⠯⠮⠍⠭|
22 |⠀⠛⠀⠨⠜⠐⠚⠍⠐⠑⠨⠙⠚⠀⠐⠪⠣⠅⠀⠀⠀⠀|
....

a pretty well formatted unicode string with Braille music score ! wow !

if you read about BrailleRAP, you know that AccesBrailleRAP, our Braille translation, software is based on eel python module. Eel allow you to embed html/javascript frontend and python backend on a packaged application for window.

So i just started a new app for AccesBrailleRAB, calling it MusicBrailleRAP, add a page and button on the react.js frontend, and drop some python lines in the backend. With a little python function, we can open a file selection dialog, convert the file to Braille characters strings with music21 and return a result as JSON for the react frontend.

@eel.expose 
def get_file_dialog():
    root = Tk()
    fname = filedialog.askopenfilename(initialdir = "./",title = "Select file",filetypes = (("musicXML","*.mxl"),("all files","*.*")))
    print (fname)
    root.destroy()
    
    linel = int (app_options['nbcol'])-1
    
    c = None

    if zipfile.is_zipfile (fname):
        with zipfile.ZipFile(fname, mode='r') as archive:
            with archive.open ('score.xml') as score:
                print ("trying to open a msz")
                data = score.read()
                c = music21.converter.parseData(data)
    else:        
        print ("trying to open a xml")
        c = music21.converter.parse (fname)
    
    bu = music21.braille.translate.objectToBraille (c, maxLineLength=linel, showHeading=True)
    
    data =str(bu)
    js = json.dumps(data)
    
    return js

After a few hours of tests and updates on the frontend and Braille paginator, i can now use MuseScore to open a music score.

i use the export feature to export the score in MusicXml format

Open MusicBrailleRAP

Use the "Open a MusicXML file", select the previously exported file .mxl

And i got this

"Et voila", just loading a paper sheet in my BrailleRAP, select a page and use the Print button. 2 minutes later i had a music score embossed on paper, ready to start some tests with unsighted musicians !

Of course there is a lot of works to do :

- Check MusicBrailleRAP is still NVDA compatible.

- Work on UX with unsighted users.

- Check that the Braille music score is friendly usable 

- Adding some error check and control on MusicBrailleRAP

- Test, share, experiment with users

But now, we have a start for a new feature. And it's exciting, what can we do with Braille music score in workshops, what can we experiment in public Fablab ... Just wait and see.

https://github.com/braillerap/MusicBrailleRAP

Discussions