Skip to main content

Wrapper for free use Google cloud TTS.

Project description

Voicy

Wrapper for free use Google Сloud TTS and STT.

Installation:

Download library using pip
$ pip3 install voicy -U

Getting the token:

For a request to the Google Cloud client need to provide a token. You can easily get it using Token object, or in a browser by yourself.

Both options are described below:

Automated option
  1. By first, you need to get API key in rucaptcha.
  2. After that import a Token object from voicy:
    from voicy import Token
  3. Then provide the API key to the get_token function:
    Token.get_token(rucaptcha_key="Key, that you got in the rucaptcha account.")
  4. If you do all alright you would get long string, that you should provide to Voice object in init.
Browser option
  1. By first, go to cloud.google.com/text-to-speech.
  2. After that scroll down to the demo part.
    Recaptcha
  3. Solve the captcha.
  4. After, open the developer console and go to the "Network" section. In column "Name" search for proxy?url=https://texttospeech.googleapis.com ...
    The developer console
    Scroll to the "Query string parameters". And here is your token.

Usage example:

For using TTS you need to provide a dictionary with a key, that is your language code and value – voice model. Format to both you can find in docs.

Simple TTS example:
from voicy import Voicy

voicy = Voicy(token="token")

print(
    voicy.tts(
        text="You are using a Voicy library. Please, give a star, if you like it.",
        voice={"en-US": "en-US-Wavenet-A"},
    )
)
This example will return File(path="84PFetz5IJdT4Je.wav", format="wav")

Simple STT example:

For using STT you only need to provide a language code. This value is the language of your audio file. Format for the language code you can find in docs.

from voicy import Voicy

voicy = Voicy(token="token")

print(
    voicy.stt(
        file="84PFetz5IJdT4Je.wav",
        language_code="en-US",
    )
)
This example will return Transcript(text="You are using a Voicy library. Please, give a star, if you like it.", confidence=0.93750596, path="84PFetz5IJdT4Je.wav", format="wav")

Google Translate TTS example:

If you don't want to get the token, you can use TTS from Google Translate. You don't need to provide anything, but the max text length for one request is 200 characters, and you can use only one voice model.

from voicy import Voicy

voicy = Voicy()

print(
    voicy.translate_tts(
        text="You are using a Voicy library. Please, give a star, if you like it.",
        language_code="en-US",
    )
)
This example will return File(path="ILSp8RHEMFyNW9M.wav", format="wav")

🤝 Contributing

Feel free to contribute.

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

voicy-0.3.1.tar.gz (7.3 kB view hashes)

Uploaded Source

Built Distribution

voicy-0.3.1-py3-none-any.whl (9.1 kB view hashes)

Uploaded Python 3

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