Skip to main content

A Media Toolkit. Text-to-speech is currently available.

Project description

Media

A Media Toolkit.

Text-to-speech is currently available.

Other features will be developed in the future.

Thanks for Microsoft Azure!

Release Note

  • 0.1.4 - 0.1.5: Fixed some issues.

  • 0.1.3:

    • Added phonemes to improve pronunciation.
    • Updated the documentation.
  • 0.1.2:

    • Added a link to the official site (Azure) to get the key.
    • Fixed some issues.
  • 0.1.1: Text-to-speech is currently available.

Quick Start

Get the keys

See "Get the keys for your resource - Azure"

Text-to-speech

from media import Voice

text = "One Piece! Dragon Ball! Doraemon! Naruto!"
voice = Voice("YourSubscriptionKey", "YourServiceRegion")
# use English
voice.speak(text)
# use Japanese
voice.speak(text, lang=Voice.LANG.JA_JP, voice_name=Voice.NAME.FEMALE.JA_JP_NANAMI)
# Save the voice file to the local
voice.save(text)

Use phonemes to improve pronunciation

from media import Voice, SSML

voice = Voice("YourSubscriptionKey", "YourServiceRegion")
ssml = SSML()
# If you want to modify the phoneme of a word, add '[]' in text
ssml.voice = {
    "text": "His name is Mike [Zhou]",
    "phonemes": [{
        "word": "Zhou",
        "alphabet": "ups",  # default: sapi
        "ph": "JH AU",
    }]
}
voice.speak(ssml)

The values ​​of alphabet and ph can refer to here, see: "Use phonemes to improve pronunciation - Azure"

Error detection

success = voice.speak()
if not success:
    # do something...
    print(voice.error)
    # do something...

View the generated XML for SSML

from media import SSML

ssml = SSML()
# for human
print(ssml)
# for program
ssml.dump()

Full Example

Text-to-speech, in a different tone.

from media import Voice, SSML

voice = Voice("YourSubscriptionKey", "YourServiceRegion")
ssml = SSML(lang=SSML.LANG.ZH_CN, voice_name=SSML.NAME.FEMALE.ZH_CN_XIAO_XUAN)
ssml.voice = "啊?"
ssml.voice = {
    "text": "这是可以说的吗?",
    "role": SSML.ROLE.YOUNG_ADULT_FEMALE,
    "style": SSML.STYLE.CHEERFUL,
    "rate": SSML.RATE.MEDIUM,
}
ssml.voice = {
    "text": "啊,可以可以",
    "name": SSML.NAME.FEMALE.ZH_CN_XIAO_MO,
    "style": SSML.STYLE.FEARFUL,
    "role": SSML.ROLE.OLDER_ADULT_FEMALE,
    "degree": "2",
}
ssml.voice = {
    "text": "没事没事",
    "name": SSML.NAME.FEMALE.ZH_CN_XIAO_MO,
    "style": SSML.STYLE.SAD,
    "role": SSML.ROLE.OLDER_ADULT_FEMALE,
    "degree": "2",
    "rate": SSML.RATE.FAST,
}
# It will play the generated speech
voice.speak(ssml)

If you want to save:

voice.save(ssml)

If you want to save and customize the name or location:

voice.save(ssml, path="这是可以说的吗.mp3")

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

media-0.1.5.tar.gz (8.5 kB view details)

Uploaded Source

Built Distribution

media-0.1.5-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

File details

Details for the file media-0.1.5.tar.gz.

File metadata

  • Download URL: media-0.1.5.tar.gz
  • Upload date:
  • Size: 8.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.0.2rc1 requests/2.24.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.6.6

File hashes

Hashes for media-0.1.5.tar.gz
Algorithm Hash digest
SHA256 aa2ba5dd1d2509f950a61c191cde5f8432c0549ceccb58b8b0af5ba146e9d61b
MD5 b83a65ccf01525dea688e04242108dec
BLAKE2b-256 0094dbcd7c54f445d0edba4c6261c2c6f2f03eb6f2bc7133f9704702e9a60936

See more details on using hashes here.

File details

Details for the file media-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: media-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 8.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.0.2rc1 requests/2.24.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.6.6

File hashes

Hashes for media-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 007b7c07c7c9f8074e7a62d6683bee81e21457ffcbae175610f63892352613ef
MD5 14e07f0b5943fe749b18c041c6c171d3
BLAKE2b-256 d8045f14fa269e300043030dcdb26c3b88b3c58cc90c07aee424a50bad27effa

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