Personal Web Api to get Decibels from an audio

I’m trying to create an app that record an audio in thunkable, save it with the cloudinary url in the format “.wav”, send it to a flask server located in my online website with pythonanywhere, download locally the audio, analyze it with Librosa and return the decibels, but it doesn’t work, any suggestions?

THUNKABLE CODE:

SOURCE CODE of the website:


from flask import Flask, request, jsonify
import requests
import librosa

app = Flask(__name__)

@app.after_request
def add_cors_headers(response):
    response.headers.add('Access-Control-Allow-Origin', '*')
    return response
    
@app.route('/upload', methods=['POST'])
def upload():
    if request.method == 'POST':
        # Ottieni l'URL dell'audio dal body della richiesta
        audio_url = request.json.get('audio_url')

        # Scarica l'audio dall'URL e salvalo localmente
        response = requests.get(audio_url)
        with open('audio.wav', 'wb') as f:
            f.write(response.content)

        # Carica l'audio utilizzando LibROSA
        y, sr = librosa.load('audio.wav')

        # Calcola i decibel dell'audio utilizzando LibROSA
        decibels = librosa.amplitude_to_db(librosa.magphase(librosa.stft(y))[0])

        # Restituisci i decibel come risposta JSON
        return jsonify({'decibels': decibels.tolist()})```
1 Like

Which part doesn’t work? Which parts do work? Are you getting an error message?

1 Like

Yea Sorry, the server work well, It gives the correct log and so on…
I think the problem is in the web api call or in the convertion of audio url, because the error is
“the browser or proxy send a request that this server could not understand” or “failed tò fetch data”. Can u revise if both code and their relation works well?

1 Like

I’m not familiar with flask servers but have you tested this on a mobile device? Do you get the same error message?

·····················································································································
Need help? How to Ask Great Questions :sparkles: Debugging A Project :sparkles: API JSON Tutorial

Want to hire a Certified Thunkable Expert? Elevate your app with Tatiang on Fiverr

1 Like

Yea on mobile i get “the browser or proxy send a request that this server could not understand". Anyone familiar with flask?

1 Like

This is the response from the web api:

<!doctype html>
<html lang=en>
<title>400 Bad Request</title>
<h1>Bad Request</h1>
<p>The browser (or proxy) sent a request that this server could not understand.</p>

1 Like

Someone good to work with Flask server in Thunkable?

1 Like

Welcome Back!
First of all, your Blocks are Incorrect,
In headers, you must not put that JSON from Object.
These Blocks Work:


But when you test it in Thunkable Live test or Web Preview, it’ll Crash Because the JSON Response is too Large with more than 200k :skull: values in a single List ( 3.57 MB) when I tested it on Postman.
Screenshot 2024-05-03 at 6.31.48 AM

Thunkable can’t Manage these Big Files, there are thousands of Objects inside the Response and It’ll be hard to Figure out a way to do it in Thunkable.
You can DM me as I can Figure out a way to Fix it in Thunkable.


Want to hire a Certified Thunkable Expert? | Get Help and Solve Issues of your thunkable Projects with whoocoder, HIRE NOW ON FIVERR! |

Thanks, whoocoder

2 Likes

Thank u, I DM u.

1 Like