Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running in python script #11

Closed
Funktionar opened this issue May 10, 2022 · 11 comments · Fixed by #17
Closed

Running in python script #11

Funktionar opened this issue May 10, 2022 · 11 comments · Fixed by #17

Comments

@Funktionar
Copy link

How can I run this in my python script, just that without text being typed in, there would be used translated_text instead:
def speak_paste(): try: spoken_text = driver1.find_element_by_xpath("/html/body/div/div[2]/div[3]/span").text test_str = (spoken_text) res = " ".join(lookp_dict.get(ele, ele) for ele in test_str.split()) pyperclip.copy(res) translator = deepl.Translator('') result = translator.translate_text((res), target_lang="ru", formality="less", preserve_formatting="1") translated_text = result.text
This is basically using subtitle text to translate it with deepl, but I want just to pass this translated text to azure tts to synthesize it.

@kxxt
Copy link
Owner

kxxt commented May 10, 2022

You can do it in two ways:

  1. Using aspeak API, but the API might change in future versions (The API is not considered stable now. That's why I didn't document it in README.md).

    from aspeak import Synthesizer

    Create a Synthesizer instance. Here is the constructor:

    class Synthesizer:
    def __init__(self, audio_config: speechsdk.audio.AudioOutputConfig = None, locale: str = 'en-US',
    voice: Union[str, None] = None, audio_format: speechsdk.SpeechSynthesisOutputFormat = None):

    For audio_config and audio_format, please refer to azure cognitive services documentation. You can also look at __main__.py and figure it out by yourself.

    Call text_to_speech/ssml_to_speech method at your choice:

    def text_to_speech(self, text: str) -> speechsdk.SpeechSynthesisResult:

    def ssml_to_speech(self, ssml: str) -> speechsdk.SpeechSynthesisResult:

  2. Using azure-cognitiveservices-speech directly.
    You can use aspeak to obtain a trial token (Note that the token will expire after a short period of time. A call to renew() will renew the token):

    from aspeak import Token
    token = Token()

    Then you can use Microsoft's official azure-cognitiveservices-speech with this trial token.
    Here is an example to create an instance of SpeechConfig using a trial token:

    import azure.cognitiveservices.speech as speechsdk
    cfg = speechsdk.SpeechConfig(auth_token=token.token, region=token.region)

@Funktionar
Copy link
Author

I did manage to synthesize it but over time it's stops working, so I assume it's the token being expired. I did try to make a define to renew the token on keyboard press but it didn't work, as it seemed like I needed to return it; could you give me a concrete example on how to refresh the token?

@kxxt
Copy link
Owner

kxxt commented May 11, 2022

I did manage to synthesize it but over time it's stops working, so I assume it's the token being expired. I did try to make a define to renew the token on keyboard press but it didn't work, as it seemed like I needed to return it; could you give me a concrete example on how to refresh the token?

If you are using the Synthesizer API, it should handle the expiration automatically.

If you just use aspeak as a way to obtain a token and then use azure-cognitiveservices-speech directly, you need to recreate the SpeechConfig object after you renewed the token.

@kxxt
Copy link
Owner

kxxt commented May 11, 2022

An easy to use python API is on the way(#12 ), I will provide examples after implementing that feature.

@Funktionar
Copy link
Author

Using the second method, I just can't call simply Token.renew(), doesn't work.

@kxxt
Copy link
Owner

kxxt commented May 11, 2022

Using the second method, I just can't call simply Token.renew(), doesn't work.

Yes, you need to recreate SpeechConfig and even SpeechSynthesizer after the renew.

@Funktionar
Copy link
Author

When will you get the API running?

@kxxt
Copy link
Owner

kxxt commented May 13, 2022

When will you get the API running?

Maybe I will release a preview version this weekend.

@kxxt
Copy link
Owner

kxxt commented May 14, 2022

When will you get the API running?

A prerelease version v2.0.0.dev1 has been released. I will write the documentations later. There are examples in https://github.com/kxxt/aspeak/tree/feat/api/src/examples

@kxxt
Copy link
Owner

kxxt commented May 14, 2022

The functional API has been stabilized in v2.0.0.dev2
Documentation available at https://github.com/kxxt/aspeak/blob/feat/api/DEVELOP.md

@kxxt kxxt closed this as completed in #17 May 16, 2022
@kxxt kxxt unpinned this issue May 16, 2022
@kxxt
Copy link
Owner

kxxt commented Oct 11, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants