Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Record audio button #113

Merged
merged 10 commits into from
Jan 15, 2024
Merged

Record audio button #113

merged 10 commits into from
Jan 15, 2024

Conversation

EloxZ
Copy link
Contributor

@EloxZ EloxZ commented Sep 18, 2023

#110

  • Added a button in freeplay TopBar to record audio
  • I'm using a recordingDestinationNode that listens every gainNode and is recorded with MediaRecorder
  • Saving file in webm to support most browsers (Tested in Edge and Firefox)

@EloxZ
Copy link
Contributor Author

EloxZ commented Sep 18, 2023

TODO:

  • Webm files doesn't support seeking, convert to wav or mp3
  • Save a MIDI file too
  • Create a window to decide location/file name
  • Load a MIDI and share it (my idea is to convert the midi file into a token to be used as parameter, but this token would be too long)

@samouri
Copy link
Contributor

samouri commented Sep 18, 2023

Load a MIDI and share it (my idea is to convert the midi file into a token to be used as parameter, but this token would be too long)

You can base64 encode the MIDI and stick it in a query param. It's fine if it is too long, since it'll only be used client side (servers never need to process it).

Copy link
Contributor

@samouri samouri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I played with the functionality and it worked well! Thank you for the contributions so far. Excited to see what you do with the "save as" dialog 😄

If you'd like, feel free to install and use the Dialog component from Radix-UI

if (isAble) {
const recordingDestinationNode = audioContext.createMediaStreamDestination();
setRecordingDestinationNode(recordingDestinationNode);
mediaRecorder = new MediaRecorder(recordingDestinationNode.stream, {mimeType: 'audio/webm'});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we default to mp3 instead of webm? I think most people using the feature would be surprised to have webm as the default

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tried but the file somehow comes corrupted. I guess we have to convert it.

src/features/audioRecording/index.ts Outdated Show resolved Hide resolved
src/features/synth/utils.ts Outdated Show resolved Hide resolved
@EloxZ
Copy link
Contributor Author

EloxZ commented Sep 19, 2023

I've made the midi recording (it only records midi message events, not pressing notes with mouse)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

useBase64Song() is called endlessly, not sure how to solve it. But the Midi file has been rebuilt properly.

image

Copy link
Contributor

@samouri samouri Jan 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Solved now by updating useSong to understand base64 as a source type

src/features/midi/utils.tsx Outdated Show resolved Hide resolved
Copy link
Contributor

@samouri samouri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@EloxZ, thank you for the updates! I didn't know about @tonejs/midi, but that seems like it'll be very useful for sightread.

In fact, I think it'd probably be better to replace the implementation of parsers/parseMidi to use @tonejs/midi instead of jasmid since it so much higher level.


Separately, is it possible you forgot to push your latest updates? I don't see any code right now that adds to the recorededMidiEvents array. Testing this resulting in an empty list


Let me know if there's anything you need help with to get this to the finish line. Some things I think it needs before it's ready:

  1. Remove all the console.log statements and unused code / some mild code cleanup
  2. It needs to function correctly
  3. Ideally a prompt to ask if you'd like to copy as a link or download as a webm/mp3, and where to save it to.

I can work on the parseMidi migration out of band

src/features/pages/PlaySong/index.tsx Outdated Show resolved Hide resolved
src/features/midi/index.tsx Outdated Show resolved Hide resolved
@samouri
Copy link
Contributor

samouri commented Oct 15, 2023

@EloxZ, let me know if you'd like to continue working on this. Otherwise I'll pick it up next week

@samouri samouri self-assigned this Oct 21, 2023
@EloxZ
Copy link
Contributor Author

EloxZ commented Nov 11, 2023

@EloxZ, let me know if you'd like to continue working on this. Otherwise I'll pick it up next week

I can continue. Did you do something?

@samouri
Copy link
Contributor

samouri commented Nov 12, 2023

@EloxZ, let me know if you'd like to continue working on this. Otherwise I'll pick it up next week

I can continue. Did you do something?

Not yet! I've been busy with other projects

Added button for recording audio in freeplay, it downloads a .webm file for broad browser support
Fix format
* Small bugfixes to the Player. Restarts song when at the end and hitting play.
* Removes support for downloading mp3-style audio. MIDI is enough for this PR,
  future one can use lamemp3 etc to convert the midi to mp3.
@samouri
Copy link
Contributor

samouri commented Jan 15, 2024

@EloxZ I've made some updates, and plan to merge it now.
After completing the recording, we now display a "Recording Preview Modal".

I've also removed the webm recording because the implementation was particularly stateful and jankey (bad enough to do it just for MIDI). An ideal implementation should be able to take the recorded midi and deterministically generate an mp3 from it, (e.g. using lamemp3 or mscore) instead of using the Web Audio API's recording capabilities.

Screen Shot 2024-01-14 at 8 44 22 PM

Thank you again for kicking this off 😄

@samouri samouri merged commit 59e0506 into sightread:main Jan 15, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants