File size: 869 Bytes
e058caf
 
988d6d5
e058caf
 
feca41c
 
 
0e3d371
 
 
 
 
e058caf
0e3d371
 
 
e058caf
 
 
 
 
 
 
 
 
 
 
0e3d371
e058caf
 
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
32
from fastapi import FastAPI, File, UploadFile
from fastapi.responses import StreamingResponse
from fastapi.middleware.cors import CORSMiddleware
import os
import io

app = FastAPI()

app.add_middleware(
    CORSMiddleware,
    allow_origins=['*']
)


@app.get("/")
def read_root():
    return {"message": "Hello World"}

@app.post("/uploadfile/")
async def create_upload_file(file: UploadFile = File(...)):
    # Save the file with a specific name
    file_path = "inputvoice.mp3"
    with open(file_path, "wb") as f:
        f.write(file.file.read())
    
    # Read the content of the saved file
    with open(file_path, "rb") as f:
        file_content = f.read()
    
    # Return the content as a streaming response
    return StreamingResponse(io.BytesIO(file_content), media_type="audio/mpeg", headers={"Content-Disposition": "inline; filename=inputvoice.mp3"})