File size: 814 Bytes
8387f59
 
e139a31
8387f59
5fbd44e
88c274c
ae5b42b
e139a31
8387f59
 
bcdc9c1
bc66078
 
dd11414
bc66078
dd11414
bcdc9c1
 
8387f59
5fbd44e
 
 
8387f59
 
5fbd44e
8387f59
5fbd44e
8387f59
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from fastapi import FastAPI, File, Form, UploadFile
import shutil
import os
app = FastAPI()

if not os.path.exists('./tarun_1234'):
    os.mkdir('./tarun_1234')

@app.post("/save_audio")
async def save_audio(audio: UploadFile = File(...), path: str = Form(...)):

    # print('PATH ************************ >>>>>', path)
    folder_path = path.split('/')[1]

    # print('FOLDER PATH ----------->>>>>>>>>>>>>>', folder_path)
    
    if not os.path.exists(folder_path):
        os.mkdir(folder_path)
    
    print("Received Audio !!!!!")

    # Save the audio to the specified path
    with open(path, "wb") as buffer:
        shutil.copyfileobj(audio.file, buffer)

    return {"message": "Audio saved successfully"}

if __name__ == '__main__':
    import uvicorn
    uvicorn.run(app, host="0.0.0.0", port=7860)