~kf5jwc/garretts-plugin-google

5a169599f701f2b9c0b5182b2492d0d95223f8d9 — Kyle Jones 2 years ago c1d71ee
Adding linter and dev packages/env
M Pipfile => Pipfile +3 -0
@@ 4,10 4,13 @@ verify_ssl = true
name = "pypi"

[packages]
text_synthesizer = "*"
google-cloud-texttospeech = "*"

[dev-packages]
mypy = "*"
black = "*"
flit = "*"

[requires]
python_version = "3.7"

M pyproject.toml => pyproject.toml +3 -0
@@ 18,3 18,6 @@ english = []

[tool.flit.entrypoints.gather]
package = "text_synthesizer_plugin_google"

[tool.black]
line-length = 88

M text_synthesizer_plugin_google/__init__.py => text_synthesizer_plugin_google/__init__.py +11 -0
@@ 11,47 11,58 @@ from typing import BinaryIO as _BinaryIO
def standard_a(text: str) -> _BinaryIO:
    return __synthesize(text, name="en-US-Standard-A")


@__plugin.register(name="Google Standard B")
def standard_b(text: str) -> _BinaryIO:
    return __synthesize(text, name="en-US-Standard-B")


@__plugin.register(name="Google Standard C")
def standard_c(text: str) -> _BinaryIO:
    return __synthesize(text, name="en-US-Standard-C")


@__plugin.register(name="Google Standard D")
def standard_d(text: str) -> _BinaryIO:
    return __synthesize(text, name="en-US-Standard-D")


@__plugin.register(name="Google Standard E")
def standard_e(text: str) -> _BinaryIO:
    return __synthesize(text, name="en-US-Standard-E")


@__plugin.register(name="Google Standard F")
def standard_f(text: str) -> _BinaryIO:
    return __synthesize(text, name="en-US-Standard-F")


# Wavenet
@__plugin.register(name="Google Wavenet A")
def wavenet_a(text: str) -> _BinaryIO:
    return __synthesize(text, name="en-US-Wavenet-A")


@__plugin.register(name="Google Wavenet B")
def wavenet_b(text: str) -> _BinaryIO:
    return __synthesize(text, name="en-US-Wavenet-B")


@__plugin.register(name="Google Wavenet C")
def wavenet_c(text: str) -> _BinaryIO:
    return __synthesize(text, name="en-US-Wavenet-C")


@__plugin.register(name="Google Wavenet D")
def wavenet_d(text: str) -> _BinaryIO:
    return __synthesize(text, name="en-US-Wavenet-D")


@__plugin.register(name="Google Wavenet E")
def wavenet_e(text: str) -> _BinaryIO:
    return __synthesize(text, name="en-US-Wavenet-E")


@__plugin.register(name="Google Wavenet F")
def wavenet_f(text: str) -> _BinaryIO:
    return __synthesize(text, name="en-US-Wavenet-F")

M text_synthesizer_plugin_google/__main__.py => text_synthesizer_plugin_google/__main__.py +6 -8
@@ 19,18 19,16 @@
import argparse
from .google import synthesize_text

if __name__ == '__main__':
if __name__ == "__main__":
    parser = argparse.ArgumentParser()
        #description=__doc__,
        #formatter_class=argparse.RawDescriptionHelpFormatter)
    parser.add_argument('--voice',
                       help="The name of the voice to use.")
    parser.add_argument('text',
                       help='The text from which to synthesize speech.')
    # description=__doc__,
    # formatter_class=argparse.RawDescriptionHelpFormatter)
    parser.add_argument("--voice", help="The name of the voice to use.")
    parser.add_argument("text", help="The text from which to synthesize speech.")

    args = parser.parse_args()

    call_args = { "text": args.text }
    call_args = {"text": args.text}
    if args.voice:
        call_args["name"] = args.voice


M text_synthesizer_plugin_google/google.py => text_synthesizer_plugin_google/google.py +15 -12
@@ 11,18 11,19 @@ def synthesize_text(text, name=None) -> BinaryIO:
    # Note: the voice can also be specified by name.
    # Names of voices can be retrieved with client.list_voices().
    opts = {
        'language_code': 'en-US',
        'ssml_gender': texttospeech.enums.SsmlVoiceGender.FEMALE
        "language_code": "en-US",
        "ssml_gender": texttospeech.enums.SsmlVoiceGender.FEMALE,
    }

    # hackity hack hack
    if name is not None:
        opts['name'] = name
        opts["name"] = name

    voice = texttospeech.types.VoiceSelectionParams(**opts)

    audio_config = texttospeech.types.AudioConfig(
        audio_encoding=texttospeech.enums.AudioEncoding.MP3)
        audio_encoding=texttospeech.enums.AudioEncoding.MP3
    )

    response = client.synthesize_speech(input_text, voice, audio_config)



@@ 39,21 40,23 @@ def list_voices() -> List[str]:

    for voice in voices.voices:
        # Display the voice's name. Example: tpc-vocoded
        print('Name: {}'.format(voice.name))
        print("Name: {}".format(voice.name))

        # Display the supported language codes for this voice. Example: "en-US"
        for language_code in voice.language_codes:
            print('Supported language: {}'.format(language_code))
            print("Supported language: {}".format(language_code))

        # SSML Voice Gender values from google.cloud.texttospeech.enums
        ssml_voice_genders = ['SSML_VOICE_GENDER_UNSPECIFIED', 'MALE',
                              'FEMALE', 'NEUTRAL']
        ssml_voice_genders = [
            "SSML_VOICE_GENDER_UNSPECIFIED",
            "MALE",
            "FEMALE",
            "NEUTRAL",
        ]

        # Display the SSML Voice Gender
        print('SSML Voice Gender: {}'.format(
            ssml_voice_genders[voice.ssml_gender]))
        print("SSML Voice Gender: {}".format(ssml_voice_genders[voice.ssml_gender]))

        # Display the natural sample rate hertz for this voice. Example: 24000
        print('Natural Sample Rate Hertz: {}\n'.format(
            voice.natural_sample_rate_hertz))
        print("Natural Sample Rate Hertz: {}\n".format(voice.natural_sample_rate_hertz))
# [END tts_list_voices]