Ejemplo n.º 1
0
def result():
    message = request.form['message']
    number = request.form['number']

    speech_config = SpeechConfig(
        subscription="0a6a0817af9f46aea9054beaa3d30290", region="westeurope")
    audio_config = AudioOutputConfig(filename="message_fr.wav")
    speech_config.speech_synthesis_voice_name = "fr-FR-DeniseNeural"
    synthesizer = SpeechSynthesizer(speech_config=speech_config,
                                    audio_config=audio_config)
    synthesizer.speak_text_async(message)

    # Add your subscription key and endpoint
    subscription_key = "e134037165514c648a57bf6ccc95e541"
    endpoint = "https://api.cognitive.microsofttranslator.com"

    # Add your location, also known as region. The default is global.
    # This is required if using a Cognitive Services resource.
    location = "francecentral"

    path = '/translate'
    constructed_url = endpoint + path

    params = {'api-version': '3.0', 'from': 'fr', 'to': ['en']}
    constructed_url = endpoint + path

    headers = {
        'Ocp-Apim-Subscription-Key': subscription_key,
        'Ocp-Apim-Subscription-Region': location,
        'Content-type': 'application/json',
        'X-ClientTraceId': str(uuid.uuid4())
    }

    # You can pass more than one object in body.
    body = [{'text': message}]

    quest = requests.post(constructed_url,
                          params=params,
                          headers=headers,
                          json=body)
    response = quest.json()

    translator = response[0]["translations"][0]["text"]

    audio_config = AudioOutputConfig(filename="message_en.wav")
    speech_config.speech_synthesis_voice_name = "en-US-AriaNeural"
    synthesizer = SpeechSynthesizer(speech_config=speech_config,
                                    audio_config=audio_config)
    synthesizer.speak_text_async(translator)

    data = {"number": number}
    with open("limit.json", "w") as file:
        json.dump(data, file)

    return (message)
def generate_voice():
    ############# AZURE #######################
    # set volume/rate/pitch -> volume default = 50
    rate = "-12%"
    pitch = "3%"
    vol_ = 10
    # AZURE 키 필요
    speech_config = SpeechConfig(subscription="APIKEY", region="eastus")
    speech_config.set_speech_synthesis_output_format(
        SpeechSynthesisOutputFormat["Riff24Khz16BitMonoPcm"])
    synthesizer = SpeechSynthesizer(speech_config=speech_config,
                                    audio_config=None)
    num_ = 0
    # text file
    with open('./tts_storage/text/tts_script.txt',
              encoding='utf-8') as file_in:
        text = ""
        for line in file_in:
            text += line
        print("## TTS script:", text)

    root = ElementTree.fromstring(
        '<speak xmlns="http://www.w3.org/2001/10/synthesis" xmlns:mstts="http://www.w3.org/2001/mstts" xmlns:emo="http://www.w3.org/2009/10/emotionml" version="1.0" xml:lang="ko-KR"><voice name="ko-KR-SunHiNeural"><prosody  volume="{}" rate="{}" pitch="{}">{}</prosody></voice></speak>'
        .format(vol_, rate, pitch, text))
    xml_script = ElementTree.ElementTree()
    ElementTree.dump(root)
    xml_script._setroot(root)
    xml_script.write('ssml.xml')
Ejemplo n.º 3
0
def generaraudio():
    archivo = open("uploads/archivo.txt", "r")
    documentos = archivo.read()
    documentos = documentos.rstrip('\n')
    synthesizer = SpeechSynthesizer(speech_config=speech_config,
                                    audio_config=audio_config)
    synthesizer.speak_text_async(documentos)
Ejemplo n.º 4
0
def voice_from_text(text, path):
    filepath = "{}/speech_{}.wav".format(path, str(uuid.uuid1().hex))
    if os.path.isfile(filepath): os.remove(filepath)

    ssml_string = """
<speak version="1.0" xmlns="http://www.w3.org/2001/10/synthesis"
    xmlns:mstts="https://www.w3.org/2001/mstts" xml:lang="en-US">
  <voice name="en-US-JennyNeural">
    <mstts:express-as style="chat">
      {}
    </mstts:express-as>
  </voice>
</speak>
    """.format(text)

    speech_config = speechsdk.SpeechConfig(
        subscription=api_keys["microsoft-speech"]["key"],
        region=api_keys["microsoft-speech"]["region"])
    # audio_config = AudioOutputConfig(filename=filepath)
    synthesizer = SpeechSynthesizer(speech_config=speech_config,
                                    audio_config=None)
    result = synthesizer.speak_ssml_async(ssml_string).get()
    stream = AudioDataStream(result)
    stream.save_to_wav_file(filepath)
    synthesizer.speak_text_async(text)

    return filepath
Ejemplo n.º 5
0
def show_action_from_speech(intent, entities):
    import matplotlib.pyplot as plt
    from azure.cognitiveservices.speech import SpeechConfig, SpeechSynthesizer, AudioConfig
    from PIL import Image
    from dotenv import load_dotenv
    import json
    import os

    action = 'unknown'
    device = 'none'
    if intent in ['switch_on', 'switch_off']:
        # Check for entities
        if len(entities) > 0:
            # Check for a device entity
            # Get the first entity (if any)
            if entities[0]["type"] == 'device':
                device = entities[0]["entity"]
                action = intent + '_' + device
        load_dotenv()
        cog_key = os.getenv('SPEECH_KEY')
        cog_location = os.getenv('SPEECH_REGION')
        response_text = "OK, I'll {} the {}!".format(intent,
                                                     device).replace("_", " ")
        speech_config = SpeechConfig(cog_key, cog_location)
        speech_synthesizer = SpeechSynthesizer(speech_config)
        result = speech_synthesizer.speak_text(response_text)

    img_name = action + '.jpg'
    img = Image.open(os.path.join("data", "luis", img_name))
    plt.axis('off')
    plt.imshow(img)
Ejemplo n.º 6
0
    def audio_tts(self, text):

        self.speech_config.set_speech_synthesis_output_format(SpeechSynthesisOutputFormat["Riff24Khz16BitMonoPcm"])
        synthesizer = SpeechSynthesizer(speech_config=self.speech_config, audio_config=None)
        ssml_string = open("ssml.xml", "r").read()
        result = synthesizer.speak_ssml_async(ssml_string).get()
        stream = AudioDataStream(result)
        stream.save_to_wav_file("/root/alfonso/ext/")
Ejemplo n.º 7
0
def tts(language, text):
    speech_config = SpeechConfig(subscription=tts_key, region=region)
    synthesizer = SpeechSynthesizer(speech_config=speech_config,
                                    audio_config=None)
    ssml_string = open("spellout/common/language.xml", "r").read()
    ssml_string = ssml_string.format(lang=language, text=text)
    result = synthesizer.speak_ssml_async(ssml_string).get()
    result = result.audio_data
    return result
Ejemplo n.º 8
0
def voice_from_text(text, path):
    filepath = "{}/speech.wav".format(path)
    if os.path.isfile(filepath): os.remove(filepath)
    
    speech_config = speechsdk.SpeechConfig(subscription=api_keys["microsoft-speech"]["key"], region=api_keys["microsoft-speech"]["region"])
    audio_config = AudioOutputConfig(filename=filepath)
    synthesizer = SpeechSynthesizer(speech_config=speech_config, audio_config=audio_config)
    synthesizer.speak_text_async("The Birch canoe slid on the smooth planks. Glue the sheet to the dark blue background.")

    return path
Ejemplo n.º 9
0
def welcome_message(name):
    speech_config = speechsdk.SpeechConfig(
        subscription="b58d19e457574aa39bc0f8b9b763cd55",
        region="australiaeast")
    audio_config = AudioOutputConfig(
        filename=
        "C:/Users/Pranav Patel/Documents/schabu/back_end/python/welcome.wav")
    synthesizer = SpeechSynthesizer(speech_config=speech_config,
                                    audio_config=audio_config)
    text = "Hello " + name + "! Welcome to Schubu Recrutiment Process. Please Click on the Start button to begin the interview process."
    synthesizer.speak_text_async(text)
    print(text)
Ejemplo n.º 10
0
 def azure_text_to_speech(self, text):
     try:
         synthesizer = SpeechSynthesizer(speech_config=self.aservice,
                                         audio_config=None)
         ssml = TSUBAKI_SSML.format(text=text)
         result = synthesizer.speak_ssml_async(ssml).get()
         data = result.audio_data
         if not data:
             logger.error(str(result.cancellation_details))
         return data
     except Exception as e:
         logger.exception("Azure Text to Speech Failiure:")
Ejemplo n.º 11
0
    def _do_tts(self, use_speaker: bool, ssml_config: str, output_file: str):
        print("Start: ", output_file)
        speech_config = SpeechConfig(subscription=self._subscription,
                                     region=self._region)
        audio_config = AudioOutputConfig(use_default_speaker=use_speaker)
        synthesizer = SpeechSynthesizer(speech_config=speech_config,
                                        audio_config=audio_config)

        result = synthesizer.speak_ssml_async(ssml_config).get()

        stream = AudioDataStream(result)
        stream.save_to_wav_file(output_file)
        print("Finished", output_file)
Ejemplo n.º 12
0
def tts(item):
    speech_config = SpeechConfig(
        subscription="bc0912f626b44d5a8bb00e4497644fa4", region="westus")
    audio_config = AudioOutputConfig(filename="./result.wav")

    synthesizer = SpeechSynthesizer(speech_config=speech_config,
                                    audio_config=audio_config)
    appendString = ""

    # if res == "OK":
    #     appendString = "is in direction you're looking"
    # else:
    #     appendString = "is not in direction you're looking"
    #

    result = synthesizer.speak_text_async(item + appendString).get()
    stream = AudioDataStream(result)
    stream.save_to_wav_file("./result.mp3")
Ejemplo n.º 13
0
async def setup_azure(filename):
    """
    Returns an Azure Speech Synthesizer pointing to the given filename
    """
    auto_detect_source_language_config = None
    speech_config = SpeechConfig(subscription=setup['azure']['key'],
                                 region=setup['azure']['region'])
    if setup['azure']['voice'] == '' or setup['azure']['voice'] == 'default':
        auto_detect_source_language_config = AutoDetectSourceLanguageConfig(
            None, None)
    else:
        speech_config.speech_synthesis_voice_name = setup['azure']['voice']
    if filename == None:
        audio_config = AudioOutputConfig(use_default_speaker=True)
    else:
        audio_config = AudioOutputConfig(filename=filename)
    synthesizer = SpeechSynthesizer(
        speech_config=speech_config,
        audio_config=audio_config,
        auto_detect_source_language_config=auto_detect_source_language_config)
    return synthesizer
Ejemplo n.º 14
0
robot = Reachy(
    right_arm=parts.RightArm(io='ws', hand='force_gripper'),
    left_arm=parts.LeftArm(io='ws', hand='force_gripper'),
)

engine = pyttsx3.init()

robot.left_arm.shoulder_roll.goal_position = 0
robot.left_arm.arm_yaw.goal_position = 0
robot.left_arm.elbow_pitch.goal_position = 0
robot.left_arm.hand.forearm_yaw.goal_position = 0

speech_config = SpeechConfig(subscription="subscriptionkey",
                             region="westeurope")
audio_config = AudioOutputConfig(use_default_speaker=True)
synthesizer = SpeechSynthesizer(speech_config=speech_config,
                                audio_config=audio_config)

ASSISTANT_API_ENDPOINT = 'embeddedassistant.googleapis.com'
END_OF_UTTERANCE = embedded_assistant_pb2.AssistResponse.END_OF_UTTERANCE
DIALOG_FOLLOW_ON = embedded_assistant_pb2.DialogStateOut.DIALOG_FOLLOW_ON
CLOSE_MICROPHONE = embedded_assistant_pb2.DialogStateOut.CLOSE_MICROPHONE
PLAYING = embedded_assistant_pb2.ScreenOutConfig.PLAYING
DEFAULT_GRPC_DEADLINE = 60 * 3 + 5

global spokenAnswer
global followUp
global followUpSentence

spokenAnswer = ""
followUpSentence = ""
followUp = False
Ejemplo n.º 15
0
from azure.cognitiveservices.language.luis.runtime import LUISRuntimeClient
from msrest.authentication import CognitiveServicesCredentials
import json

luis_app_id = '20263b4d-b405-4c9b-8de8-e51663797c41' 
luis_key = 'b45490c8a83243f9a6320ec7e8e85a43'
luis_endpoint = 'https://koinonos-language-understanding.cognitiveservices.azure.com/'

# Configure speech recognizer
speech_key, service_region = "40a03ef9d3d44916bdcd1c4457b82c13", "eastus" 
speech_config = SpeechConfig(subscription=speech_key, region=service_region)
speech_recognizer = SpeechRecognizer(speech_config=speech_config)

# Configure speech synthesizer
audio_config = AudioOutputConfig(use_default_speaker=True)
synthesizer = SpeechSynthesizer(speech_config=speech_config)

runtimeCredentials = CognitiveServicesCredentials(luis_key)
clientRuntime = LUISRuntimeClient(endpoint=luis_endpoint, credentials=runtimeCredentials)

print("Start listening...")
speech = speech_recognizer.recognize_once()
try:   
    while speech.text != "Stop":
        # Production == slot name
        print("Your query is: ", speech.text)
        predictionRequest = { "query" : speech.text}

        predictionResponse = clientRuntime.prediction.get_slot_prediction(luis_app_id, "Production", predictionRequest)
        
        print("Top intent: {}".format(predictionResponse.prediction.top_intent))