streamlit-rec


Namestreamlit-rec JSON
Version 0.0.5 PyPI version JSON
download
home_pageNone
SummaryAudio recorder component for streamlit
upload_time2024-04-30 06:39:36
maintainerNone
docs_urlNone
authorBenson Sung
requires_python>=3.6
licenseNone
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            [![Streamlit App](https://static.streamlit.io/badges/streamlit_badge_black_white.svg)](https://audio-recorder.streamlit.app)
# streamlit-audiorecorder

### An audio Recorder for streamlit

#### Description
Audio recorder component for streamlit.  
It creates a button to start the recording and takes three arguments: the start button text, the stop button text, and the pause button text.  
If the pause button text is not specified, the pause button is not displayed.

#### Return value
The component's return value is a [pydub](https://github.com/jiaaro/pydub/) [`AudioSegment`](https://github.com/jiaaro/pydub/blob/master/API.markdown#audiosegment).  
All `AudioSegment` methods are available, in particular you can:
- Play the audio in the frontend with `st.audio(audio.export().read())`
- Save the audio to a file with `audio.export("audio.wav", format="wav")`

### Installation:
```bash
pip install streamlit_rec
```
Note: This package uses ffmpeg, so it should be installed for this audiorecorder to work properly.

On ubuntu/debian: `sudo apt update && sudo apt install ffmpeg`  
On mac: `brew install ffmpeg`

### Usage:
```python
import streamlit as st
from streamlit_rec import audiorecorder

st.title("Audio Recorder")
audio = audiorecorder()

if len(audio) > 0:
    # To play audio in frontend:
    st.audio(audio.export().read())  

    # To save audio to a file, use pydub export method:
    audio.export("audio.wav", format="wav")

    # To get audio properties, use pydub AudioSegment properties:
    st.write(f"Frame rate: {audio.frame_rate}, Frame width: {audio.frame_width}, Duration: {audio.duration_seconds} seconds")
```

---
### Troubleshooting:

**Error**: No record button is shown and you get the following error message in the console:
 ```console
 Component Error
 Cannot read properties of undefined (reading 'getUserMedia')
 ```
**Reason**: To record the audio, this component uses the `MediaDevices`` interface.  
For security reasons, the `getUserMedia()` method is available only in secure contexts (HTTPS), as explained in the
[MDM documentation](https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia) :

> As an API that may involve significant privacy concerns, getUserMedia()'s specification lays out a wide array of privacy and security requirements that browsers are obligated to meet.
> 
> getUserMedia() is a powerful feature that can only be used in secure contexts; in insecure contexts, navigator.mediaDevices is undefined, preventing access to getUserMedia(). A secure context is, in short, a page loaded using HTTPS or the file:/// URL scheme, or a page loaded from localhost.

**Solution**: Serve your website using HTTPS. If you are serving your website locally, make sure to access it using `localhost`, not an IP address.

Just solved this problem.

1.Generate temporary SSL authentication
```console
openssl genrsa 2048 > host.key
chmod 400 host.key
openssl req -new -x509 -nodes -sha256 -days 365 -key host.key -out host.cert
```

2.streamlit run with https
```console
streamlit run xx.py --server.sslCertFile host.cert --server.sslKeyFile=host.key
```

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "streamlit-rec",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": null,
    "keywords": null,
    "author": "Benson Sung",
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/06/cc/a9e605151a147e96a813e6ff8e87e6086412c94f8567fb4020dfc932bcc9/streamlit_rec-0.0.5.tar.gz",
    "platform": null,
    "description": "[![Streamlit App](https://static.streamlit.io/badges/streamlit_badge_black_white.svg)](https://audio-recorder.streamlit.app)\n# streamlit-audiorecorder\n\n### An audio Recorder for streamlit\n\n#### Description\nAudio recorder component for streamlit.  \nIt creates a button to start the recording and takes three arguments: the start button text, the stop button text, and the pause button text.  \nIf the pause button text is not specified, the pause button is not displayed.\n\n#### Return value\nThe component's return value is a [pydub](https://github.com/jiaaro/pydub/) [`AudioSegment`](https://github.com/jiaaro/pydub/blob/master/API.markdown#audiosegment).  \nAll `AudioSegment` methods are available, in particular you can:\n- Play the audio in the frontend with `st.audio(audio.export().read())`\n- Save the audio to a file with `audio.export(\"audio.wav\", format=\"wav\")`\n\n### Installation:\n```bash\npip install streamlit_rec\n```\nNote: This package uses ffmpeg, so it should be installed for this audiorecorder to work properly.\n\nOn ubuntu/debian: `sudo apt update && sudo apt install ffmpeg`  \nOn mac: `brew install ffmpeg`\n\n### Usage:\n```python\nimport streamlit as st\nfrom streamlit_rec import audiorecorder\n\nst.title(\"Audio Recorder\")\naudio = audiorecorder()\n\nif len(audio) > 0:\n    # To play audio in frontend:\n    st.audio(audio.export().read())  \n\n    # To save audio to a file, use pydub export method:\n    audio.export(\"audio.wav\", format=\"wav\")\n\n    # To get audio properties, use pydub AudioSegment properties:\n    st.write(f\"Frame rate: {audio.frame_rate}, Frame width: {audio.frame_width}, Duration: {audio.duration_seconds} seconds\")\n```\n\n---\n### Troubleshooting:\n\n**Error**: No record button is shown and you get the following error message in the console:\n ```console\n Component Error\n Cannot read properties of undefined (reading 'getUserMedia')\n ```\n**Reason**: To record the audio, this component uses the `MediaDevices`` interface.  \nFor security reasons, the `getUserMedia()` method is available only in secure contexts (HTTPS), as explained in the\n[MDM documentation](https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia) :\n\n> As an API that may involve significant privacy concerns, getUserMedia()'s specification lays out a wide array of privacy and security requirements that browsers are obligated to meet.\n> \n> getUserMedia() is a powerful feature that can only be used in secure contexts; in insecure contexts, navigator.mediaDevices is undefined, preventing access to getUserMedia(). A secure context is, in short, a page loaded using HTTPS or the file:/// URL scheme, or a page loaded from localhost.\n\n**Solution**: Serve your website using HTTPS. If you are serving your website locally, make sure to access it using `localhost`, not an IP address.\n\nJust solved this problem.\n\n1.Generate temporary SSL authentication\n```console\nopenssl genrsa 2048 > host.key\nchmod 400 host.key\nopenssl req -new -x509 -nodes -sha256 -days 365 -key host.key -out host.cert\n```\n\n2.streamlit run with https\n```console\nstreamlit run xx.py --server.sslCertFile host.cert --server.sslKeyFile=host.key\n```\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Audio recorder component for streamlit",
    "version": "0.0.5",
    "project_urls": null,
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "2562562197226b7bb3e10b9e3fabdae82c48051140e82e7f32532575207b61b8",
                "md5": "223819d92e5fc845551dd7b3fb903c5b",
                "sha256": "6145a91f898e0e85e46803811e9009f51e430353692fc7e85bb29036ae46b9a8"
            },
            "downloads": -1,
            "filename": "streamlit_rec-0.0.5-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "223819d92e5fc845551dd7b3fb903c5b",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 1497447,
            "upload_time": "2024-04-30T06:39:32",
            "upload_time_iso_8601": "2024-04-30T06:39:32.916691Z",
            "url": "https://files.pythonhosted.org/packages/25/62/562197226b7bb3e10b9e3fabdae82c48051140e82e7f32532575207b61b8/streamlit_rec-0.0.5-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "06cca9e605151a147e96a813e6ff8e87e6086412c94f8567fb4020dfc932bcc9",
                "md5": "8b7c747307ee1716f29e3bc57304eba6",
                "sha256": "e5e448c9d56681eeef05b858c38d647b8f34b006535842f17ff957807839a8bb"
            },
            "downloads": -1,
            "filename": "streamlit_rec-0.0.5.tar.gz",
            "has_sig": false,
            "md5_digest": "8b7c747307ee1716f29e3bc57304eba6",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 521074,
            "upload_time": "2024-04-30T06:39:36",
            "upload_time_iso_8601": "2024-04-30T06:39:36.625589Z",
            "url": "https://files.pythonhosted.org/packages/06/cc/a9e605151a147e96a813e6ff8e87e6086412c94f8567fb4020dfc932bcc9/streamlit_rec-0.0.5.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-30 06:39:36",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "streamlit-rec"
}
        
Elapsed time: 1.08381s