Skip to content

Media API Implementation

Ruinan edited this page Mar 30, 2017 · 2 revisions

By Ruinan Wang and David Tran

Goal

Currently, the ebook supports image manipulation for the media comp API in active code, but not sound manipulation, which is what we are trying to integrate. To do this, we are adding a new sound module in skulpt, which could recognize sound manipulation code in python and display the results on the browser for students to see and hear.

SKULPT

What is skulpt?

Skulpt is an entirely in-browser implementation of Python written in JavaScript. Python code is taken in, processed through skulpt, and the results are displayed in the browser. Try it out here. In the Student CSP ebook, skulpt is used in all of the active code exercises.

Here is an example from the ebook.

Building and using skulpt

In order to use skulpt you will need to download the skulpt folder through GitHub. In order to build your own usable version you will first need to install Python 2 and node.js. To install dependencies run ”npm install”. Make sure you are in the main directory of the skulpt folder and run “npm run build”. After running that you will find skulpt.min.js and skulpt-stdlib.js in the distfolder. Skulpt.min.js is the minimal version of skulpt that must be included in a web page in order for skulpt to work, and skulpt-stdlib.js contains the modules for skulpt (media, turtles…). These would be the two files you would need to put into the runestone project.

After you build the ebook, you can find these files under build/StudentCSP/_static. In order to change which version of skulpt gets uploaded to this location then you will need to go into your Python 2.7 folder and navigate to the python libraries to site-packages. Under runestone/activecode/js you will find a skulpt.min.js and skulpt-stdlib.js file. All of the files in this folder are the files that eventually end up in the _static folder in the built ebook. You can add files to this folder so that they are automatically added to the ebook.

Check out more information here.

Pythy

What is pythy and why are we using it?

Pythy is a cloud-based IDE for python. Pythy uses skulpt to process python code so that it can be run inside of a web-browser. Pythy also utilizes a similar media computation API that the ebook uses, including having a working sound API. We are hoping to be able to use the working Pythy sound code, and integrate it into our ebook, rather than building a new sound API from scratch.

Our approach

Skulpt supports modifiable libraries, (found under src/lib) where users are able to create and upload their own. Since pythy has a working sound library inside the skulpt file, we attempted replacing our current skulpt with the version pythy uses. However, the skulpt file that pythy uses is dependent on the main pythy application, which lead to issues trying to compile code (since it referencing to code that do not exist in our ebook). This means that we now need to find the dependencies within pythy and attempt to refactor that code to make it usable in our ebook.

Current issues/limitations

The current issues we are facing is using the code based in pythy. We are having difficulty finding the needed files that skulpt depends on to run. The next step is to create our own running version of pythy so that we can obtain the needed build files; however, due to outdated plugins we are having issues building this application.