stefanrmmr / streamlit-audio-recorder

Record Audio from the User's Microphone in Apps that are Deployed to the Web. (via Browser Media-API, REACT-based, Streamlit Custom Component)
MIT License
415 stars 75 forks source link

Access data from Python #2

Closed jingzhaoou closed 2 years ago

jingzhaoou commented 2 years ago

I just found out this project from Stack Overflow. I gave it a try and things work great! A pity that I don't see a way to access the data from Python. If you have any hints how that can be done, I am more than happy to help out. Thanks a lot!

Jackiexiao commented 2 years ago

if it save wav to disk? @stefanrmmr

stefanrmmr commented 2 years ago

Hi @Jackiexiao @jingzhaoou,

Please have a look at my current efforts and reach out to me in case you know of alternative approaches I could test.

There exist various scripts that enable saving audio to a local disk. However, none of these solutions work in an online-deployed scenario. (the program would save to the server's disk instead of the user's). This is why I came to the conclusion that this issue requires a solution that uses the audio data which is stored in the user's browser cache after being recorded.

The data stored in this cache via the audio-blob format, can not directly be passed back to python as a return variable and needs to be converted to an "environment agnostic datatype" (I tried binary base64). This conversion's complexity scales exponentially with the length of the audio data. Therefore I considered splitting the audio-blob into slices which can then be converted, aggregated and returned to Python. However, this process of splitting and concatenating WAV-audio blobs was not possible for me to implement due to the data structure/metadata inside the wav-file and the lack of libraries that would enable audio-blob slicing etc.

jingzhaoou commented 2 years ago

Sorry for the late reply. I was swamped with my work earlier. I played with the Audio component with Gradio (https://gradio.app/docs/#audio), which works pretty well. I investigated and it seems Gradio saves the audio as a wav file on the server. Thus, I feel that saving the audios on the server disk could be acceptable solution here.

Jackiexiao commented 2 years ago

@jingzhaoou thx for sharing!