Soporte & Consultoria

Soporte Remoto y Consultoria skype : ambiorixg12.
Nota no se brinda ningun tipo de consulta o soporte fuera del blog de forma gratuita

lunes, 23 de septiembre de 2024

google tts asterisk using python virtual env

 [vaccine-rev]

exten=>100,1,Answer()

same=>n,Set(fname=${CHANNEL})

same=>n,agi(/var/www/html/google_tts/tts.py,${fname:4},"Total number of students registered with this telephone number.")

same=>n,playback(/var/www/html/google_tts/audios/${fname:4})

same=>n,Saynumber(3)

same=>n,agi(/var/www/html/google_tts/tts.py,${fname:4},"David is missing the following vaccines:")

same=>n,playback(/var/www/html/google_tts/audios/${fname:4})


same=>n,hangup()

---------
#!/var/www/html/google_tts/myenv/bin/python3

import os
import sys

import google.cloud.texttospeech as tts

# Set the path to your Google Cloud credentials
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "/var/www/html/google_tts/voice.json"

def text_to_wav(voice_name: str, text: str):
    language_code = "-".join(voice_name.split("-")[:2])
    text_input = tts.SynthesisInput(text=text)
    voice_params = tts.VoiceSelectionParams(
        language_code=language_code, name=voice_name
    )

    # Set the audio configuration with 8000 Hz sample rate
    audio_config = tts.AudioConfig(
        audio_encoding=tts.AudioEncoding.LINEAR16,
        sample_rate_hertz=8000  # Set sample rate to 8000 Hz
    )

    client = tts.TextToSpeechClient()
    response = client.synthesize_speech(
        input=text_input,
        voice=voice_params,
        audio_config=audio_config,
    )

    # Change the path to save the file in the desired location
    filename = f"/var/www/html/google_tts/audios/{sys.argv[1]}.wav"  # Specify the desired save path
    with open(filename, "wb") as out:
        out.write(response.audio_content)
        print(f'Generated speech saved to "{filename}"')

# Ensure the command line argument is provided
if len(sys.argv) > 1:
    text_to_wav("en-US-Studio-O", sys.argv[2])


#######

(myenv) [root@freepbx google_tts]# pip list
Package                   Version
------------------------- ---------
cachetools                4.2.4
certifi                   2024.8.30
charset-normalizer        2.0.12
google-api-core           2.8.2
google-auth               2.22.0
google-cloud-texttospeech 2.11.1
googleapis-common-protos  1.56.3
grpcio                    1.48.2
grpcio-status             1.48.2
idna                      3.10
pip                       21.3.1
proto-plus                1.23.0
protobuf                  3.19.6
pyasn1                    0.5.1
pyasn1-modules            0.3.0
requests                  2.27.1
rsa                       4.9
setuptools                39.2.0
six                       1.16.0
urllib3                   1.26.20
(myenv) [root@freepbx google_tts]# pip freeze
cachetools==4.2.4
certifi==2024.8.30
charset-normalizer==2.0.12
google-api-core==2.8.2
google-auth==2.22.0
google-cloud-texttospeech==2.11.1
googleapis-common-protos==1.56.3
grpcio==1.48.2
grpcio-status==1.48.2
idna==3.10
proto-plus==1.23.0
protobuf==3.19.6
pyasn1==0.5.1
pyasn1-modules==0.3.0
requests==2.27.1
rsa==4.9
six==1.16.0
urllib3==1.26.20




No hay comentarios:

Publicar un comentario