Exemple #1
0
def image_to_text_handler():
    id_token = request.cookies.get("token")
    claims = None
    error_message = None
    try:
        claims = google.oauth2.id_token.verify_firebase_token(
            id_token, firebase_request_adapter)
    except ValueError as exc:
        error_message = str(exc)
    print(claims['email'])

    image_data = request.files['image_data'].read()
    output_language = request.form['to']
    text_from_image = image_to_text.get_text(image_data)
    translated_text = text_to_text.translate(text_from_image, output_language)
    return translated_text
Exemple #2
0
def text_to_speech_handler():
    id_token = request.cookies.get("token")
    claims = None
    error_message = None
    try:
        claims = google.oauth2.id_token.verify_firebase_token(
            id_token, firebase_request_adapter)
    except ValueError as exc:
        error_message = str(exc)
    print(claims['email'])

    input_text = request.args['input_text']
    output_language = request.args['to']
    translated_text = text_to_text.translate(input_text, output_language)
    audio_data = text_to_speech.translate(translated_text, output_language)
    return audio_data
Exemple #3
0
def speech_to_speech_handler():
    id_token = request.cookies.get("token")
    claims = None
    error_message = None
    try:
        claims = google.oauth2.id_token.verify_firebase_token(
            id_token, firebase_request_adapter)
    except ValueError as exc:
        error_message = str(exc)
    print(claims['email'])

    speech_data = request.files['speech_data'].read()
    input_language = request.form['from']
    output_language = request.form['to']
    text_from_speech = speech_to_text.get_text(speech_data, input_language)
    translated_text = text_to_text.translate(text_from_speech, output_language)
    audio_data = text_to_speech.translate(translated_text, output_language)
    return audio_data
Exemple #4
0
def text_to_text_handler():
    input_text = request.args['input_text']
    output_language = request.args['to']
    translated_text = text_to_text.translate(input_text, output_language)
    return translated_text