Die Anfragen werden unten angezeigt:
Code: Select all
file_id = {
"audio_id": "f7d0a1d2-095d-432a-bf0f-22c445a433c0"
}
def file_upload():
with wave.open(f"..\\audioFilePath\\{file_id['audio_id']}.wav", "rb") as f:
audio_files = f.readframes(f.getnframes())
params = f.getparams()
response = requests.post(
"http://127.0.0.1:8000/save",
data={
"audio_file":audio_files,
"audio_id":file_id['audio_id'],
"channle":params[0],
"sampwidth":params[1],
"framerate":params[2],
"nframes":params[3],
},
)
print(response)
der Beitrag meines Servers unter FastAPI:
Code: Select all
@app.post("/save")
async def file_save(
audio_file: bytes = Body(..., title="wav_binary_file"),
audio_id: str = Body(..., title="uuid"),
channle: int = Body(..., title="channle"),
sampwidth: int = Body(..., title="sampwidth"),
framerate: int = Body(..., title="framerate"),
nframes: int = Body(..., title="nframes"),
):
sound_id.Audio_Id = audio_id
print(audio_file)
# write .wav file
with wave.open(f"..\\temp_audio\\{audio_id}.wav", mode="wb") as w:
w.setnchannels(channle)
w.setsampwidth(sampwidth)
w.setframerate(framerate)
w.setnframes(nframes)
w.writeframes(audio_file)
Könnten Sie mir einen Rat geben?
Mobile version