Skip to main content

The package contains a ready-to-use streamlit widget for downloading or recording audio. There is support for most audio formats.

Project description

sound-streamlit

sound-streamlit is a custom widget for working with audio built into streamlit. You only need to import one class that will allow you to record or load audio. Any audio format is supported, and in the parameters you can set the sample rate, minimum or maximum audio length and much more. Ask any questions. I will be very grateful if you rate the repository ⭐️

Installation & setup

1. Install widget from PyPI

pip install sound-streamlit

2. Make sure that you have the C++ ffmpeg library installed on your computer.


Its absence will lead to an error.
If you are not sure that you have it, then run the command below (only for Unix)

sudo apt install ffmpeg

How to use?

import package with widget

from soundlit import AudioWidget

initialize component

# Custom streamlit component for audio recording and uploading
widget = AudioWidget()  

# You can see params of AudioWidget belove:
# min_duration: minimum duration of audio file (By default: 0 seconds)
# max_duration: maximum duration of audio file (By default: 60_000 seconds)
# available_formats: audio files with which formats available for uploading
# convert_to: what format to convert an audio file into if it needs to be converted (By default .wav)
# execlude_convert: audio files with which formats do not require conversion to a supported format
# sample_rate: sampling rate to which the audio file will be resampled
# mono: convert waveform to mono format with one channel if True else load 2 channels

use only recorder

audio = widget.record_audio()

or only uploader for all audio formats

audio = widget.load_audio()

and finally you can use the whole widget

audio = widget.get_audio()

How change recoder style?

1. Install node >= 16

2. Go to the cloned project directory, then to the 'soundlit/recorder' package, and finally to the fronted folder.

cd ./soundlit/recorder/frontend

3. Install all fronted dependencies

npm i

4. Set Node options for legacy support

on Unix-like (Linux, macOS, Git bash, etc.)

export NODE_OPTIONS=--openssl-legacy-provider

on Windows command prompt

set NODE_OPTIONS=--openssl-legacy-provider

on PowerShell

$env:NODE_OPTIONS = "--openssl-legacy-provider"

5. Change component style

go to the file StreamlitAudioRecorder.tsx at the path below in any text editor

cd ./soundlit/recorder/frontend/src/StreamlitAudioRecorder.tsx

and change the styles that start from line 59

<AudioReactRecorder
state={recordState}
onStop={this.onStop_audio}
type='audio/wav'
backgroundColor='#000000'
foregroundColor='#6633CC'
canvasWidth={450}
canvasHeight={100}
/>

6. Remove current frontend build

rm -rf ./soundlit/recorder/frontend/build

7. Build new fronted comnponent

npm run build

8. Remove all dependencies unless you no longer need to change the style

on Unix-like (Linux, macOS)

rm -rf node_modules

on Windows

npm i -g rm
rm -rf node_modules

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sound-streamlit-0.1.7.tar.gz (875.9 kB view details)

Uploaded Source

File details

Details for the file sound-streamlit-0.1.7.tar.gz.

File metadata

  • Download URL: sound-streamlit-0.1.7.tar.gz
  • Upload date:
  • Size: 875.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.13

File hashes

Hashes for sound-streamlit-0.1.7.tar.gz
Algorithm Hash digest
SHA256 897499949387d21382074dbae23da7e049ed53d33e2c64e69764cb2f3e5a659f
MD5 2ca9e2ee8709d6f5934f1516f36134d9
BLAKE2b-256 f562dc13edf65728b20b70a953dbb80c49f472d06316d4bd9c0a75e0994531a3

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page