def upload_audio()

in speech/main.py [0:0]


def upload_audio():
    # Create a Cloud Storage client.
    storage_client = storage.Client()

    # Get the Cloud Storage bucket that the file will be uploaded to.
    bucket = storage_client.get_bucket(os.environ.get('CLOUD_STORAGE_BUCKET'))

    # Create a new blob and upload the file's content to Cloud Storage.
    audio = request.files['file']
    blob = bucket.blob(audio.filename)
    blob.upload_from_string(
            audio.read(), content_type=audio.content_type)

    # Retrieve a Speech API response for the audio file stored in Cloud Storage
    source_uri = 'gs://{}/{}'.format(os.environ.get('CLOUD_STORAGE_BUCKET'), blob.name)
    response = transcribe_audio(source_uri)
    results = response.results
    
    # Redirect to the home page.
    return render_template('homepage.html', results=results)