streamlit-TTS


Namestreamlit-TTS JSON
Version 0.0.7 PyPI version JSON
download
home_pagehttps://github.com/B4PT0R/streamlit-TTS
SummaryStreamlit component providing tools to convert text to speech and play audio directly in the browser
upload_time2024-01-14 20:07:17
maintainer
docs_urlNone
authorBaptiste Ferrand
requires_python>=3.7
license
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # streamlit-TTS

Streamlit component providing some tools to convert text to speech and autoplay the audio directly in the browser in an invisible iframe.

## Installation instructions

```sh
pip install streamlit-TTS
```

## Usage instructions

Three functions are provided:

1.

```python
auto_play(audio,wait=True,lag=0.25,key=None)
```
Plays some audio directly in the browser without showing an audio player.
The iframe containing the component is made invisible and shouldn't mess with the app's layout.
`audio` must be a dict with the following structure:

```python
audio={
    'bytes':bytes, # wav audio bytes
    'sample_rate':sample_rate, # the sample rate of the audio
    'sample_width':sample_width, # the sample width of the audio
    ... # possibly other keys that will be ignored by the function
}
```

`wait` determines whether the component should pause execution of the python script until the audio has finished playing (avoids putting another audio on play while the previous one is still playing). Since there is no easy way, given the constraints of streamlit implementation, to get instant information from the front-end whether it has finished playing or not, the waiting time is calculated based on the duration of the audio passed. Works generally well, but can sometimes give poor results, depending on the communication lag between front end and back end. `lag` (in seconds) allows to adapt to this lag by waiting a bit more time to let the audio finish playing before resuming execution.

2.

```python
audio=text_to_audio(text,language='en',cleanup_hook=None)
```

Converts some text in the chosen language into spoken audio (uses gTTS and pydub).
A default cleanup of the text is being implemented before passing it to vocal synthesis (Markdown syntax elements, LaTeX formulas, links, long code snippets are removed). But you can pass your own as the `cleanup_hook` if you want more control. 
The audio returned is a dictionary with the same structure as accepted by `auto_play`.
(This function is provided for convenience, it's not a streamlit component.)

3.
```python
text_to_speech(text,language='en',cleanup_hook=None,wait=True,lag=0.25,key=None)
```

Builds on the first two functions to convert text into speech and play the audio directly.


## Example
```python
import streamlit as st
from streamlit_TTS import auto_play, text_to_speech, text_to_audio

from gtts.lang import tts_langs

langs=tts_langs().keys()

#get the audio first
audio=text_to_audio("Choose a language, type some text, and click 'Speak it out!'.",language='en')
#then play it
auto_play(audio)

lang=st.selectbox("Choose a language",options=langs)
text=st.text_input("Choose a text to speak out:")
speak=st.button("Speak it out!")

if lang and text and speak:
    #plays the audio directly
    text_to_speech(text=text, language=lang)
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/B4PT0R/streamlit-TTS",
    "name": "streamlit-TTS",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "",
    "keywords": "",
    "author": "Baptiste Ferrand",
    "author_email": "bferrand.maths@gmail.com.com",
    "download_url": "https://files.pythonhosted.org/packages/94/d1/921381eb32ec35821f09336ed21a5f5a528488aec71ccfddb67b63c90df5/streamlit_TTS-0.0.7.tar.gz",
    "platform": null,
    "description": "# streamlit-TTS\n\nStreamlit component providing some tools to convert text to speech and autoplay the audio directly in the browser in an invisible iframe.\n\n## Installation instructions\n\n```sh\npip install streamlit-TTS\n```\n\n## Usage instructions\n\nThree functions are provided:\n\n1.\n\n```python\nauto_play(audio,wait=True,lag=0.25,key=None)\n```\nPlays some audio directly in the browser without showing an audio player.\nThe iframe containing the component is made invisible and shouldn't mess with the app's layout.\n`audio` must be a dict with the following structure:\n\n```python\naudio={\n    'bytes':bytes, # wav audio bytes\n    'sample_rate':sample_rate, # the sample rate of the audio\n    'sample_width':sample_width, # the sample width of the audio\n    ... # possibly other keys that will be ignored by the function\n}\n```\n\n`wait` determines whether the component should pause execution of the python script until the audio has finished playing (avoids putting another audio on play while the previous one is still playing). Since there is no easy way, given the constraints of streamlit implementation, to get instant information from the front-end whether it has finished playing or not, the waiting time is calculated based on the duration of the audio passed. Works generally well, but can sometimes give poor results, depending on the communication lag between front end and back end. `lag` (in seconds) allows to adapt to this lag by waiting a bit more time to let the audio finish playing before resuming execution.\n\n2.\n\n```python\naudio=text_to_audio(text,language='en',cleanup_hook=None)\n```\n\nConverts some text in the chosen language into spoken audio (uses gTTS and pydub).\nA default cleanup of the text is being implemented before passing it to vocal synthesis (Markdown syntax elements, LaTeX formulas, links, long code snippets are removed). But you can pass your own as the `cleanup_hook` if you want more control. \nThe audio returned is a dictionary with the same structure as accepted by `auto_play`.\n(This function is provided for convenience, it's not a streamlit component.)\n\n3.\n```python\ntext_to_speech(text,language='en',cleanup_hook=None,wait=True,lag=0.25,key=None)\n```\n\nBuilds on the first two functions to convert text into speech and play the audio directly.\n\n\n## Example\n```python\nimport streamlit as st\nfrom streamlit_TTS import auto_play, text_to_speech, text_to_audio\n\nfrom gtts.lang import tts_langs\n\nlangs=tts_langs().keys()\n\n#get the audio first\naudio=text_to_audio(\"Choose a language, type some text, and click 'Speak it out!'.\",language='en')\n#then play it\nauto_play(audio)\n\nlang=st.selectbox(\"Choose a language\",options=langs)\ntext=st.text_input(\"Choose a text to speak out:\")\nspeak=st.button(\"Speak it out!\")\n\nif lang and text and speak:\n    #plays the audio directly\n    text_to_speech(text=text, language=lang)\n```\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "Streamlit component providing tools to convert text to speech and play audio directly in the browser",
    "version": "0.0.7",
    "project_urls": {
        "Homepage": "https://github.com/B4PT0R/streamlit-TTS"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "12272f2df47b552d8cd64e717e640271b6980b321012807b829c094a21d82b5a",
                "md5": "6a325ce0b9e08934be0c536aa682ae9d",
                "sha256": "1cd17d01bd1164fcc5ed9202ec3dcc6f4657e8bca1ad741b239fda403ab42516"
            },
            "downloads": -1,
            "filename": "streamlit_TTS-0.0.7-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "6a325ce0b9e08934be0c536aa682ae9d",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 446374,
            "upload_time": "2024-01-14T20:07:15",
            "upload_time_iso_8601": "2024-01-14T20:07:15.426017Z",
            "url": "https://files.pythonhosted.org/packages/12/27/2f2df47b552d8cd64e717e640271b6980b321012807b829c094a21d82b5a/streamlit_TTS-0.0.7-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "94d1921381eb32ec35821f09336ed21a5f5a528488aec71ccfddb67b63c90df5",
                "md5": "0deebc04f0dd3b4f1e3004eca57aeb5c",
                "sha256": "24ad2068fd5e416c1d8fa6f9c1dd65efdf3544b75ce6a79e2676e3a529ddc9a6"
            },
            "downloads": -1,
            "filename": "streamlit_TTS-0.0.7.tar.gz",
            "has_sig": false,
            "md5_digest": "0deebc04f0dd3b4f1e3004eca57aeb5c",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 443390,
            "upload_time": "2024-01-14T20:07:17",
            "upload_time_iso_8601": "2024-01-14T20:07:17.861004Z",
            "url": "https://files.pythonhosted.org/packages/94/d1/921381eb32ec35821f09336ed21a5f5a528488aec71ccfddb67b63c90df5/streamlit_TTS-0.0.7.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-01-14 20:07:17",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "B4PT0R",
    "github_project": "streamlit-TTS",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "streamlit-tts"
}
        
Elapsed time: 0.18689s