mirror of
https://github.com/LostRuins/koboldcpp.git
synced 2025-09-10 17:14:36 +00:00
fix for uploaded wav files being incomplete due to fragmentation when converting to b64
This commit is contained in:
parent
a9dbcdd3ec
commit
6da5a63852
2 changed files with 12 additions and 4 deletions
11
koboldcpp.py
11
koboldcpp.py
|
@ -1415,10 +1415,13 @@ class ServerRequestHandler(http.server.SimpleHTTPRequestHandler):
|
|||
detected_upload_filename = re.findall(r'Content-Disposition.*name="file"; filename="(.*)"', fpart.decode('utf-8',errors='ignore'))
|
||||
if detected_upload_filename and len(detected_upload_filename)>0:
|
||||
utfprint(f"Detected uploaded file: {detected_upload_filename[0]}")
|
||||
file_data = fpart.split(b'\r\n\r\n')[1].rsplit(b'\r\n', 1)[0]
|
||||
file_data_base64 = base64.b64encode(file_data).decode('utf-8',"ignore")
|
||||
base64_string = f"data:audio/wav;base64,{file_data_base64}"
|
||||
return base64_string
|
||||
file_content_start = fpart.find(b'\r\n\r\n') + 4 # Position after headers
|
||||
file_content_end = fpart.rfind(b'\r\n') # Ending boundary
|
||||
if file_content_start != -1 and file_content_end != -1:
|
||||
file_data = fpart[file_content_start:file_content_end]
|
||||
file_data_base64 = base64.b64encode(file_data).decode('utf-8',"ignore")
|
||||
base64_string = f"data:audio/wav;base64,{file_data_base64}"
|
||||
return base64_string
|
||||
print("Uploaded file not found.")
|
||||
return None
|
||||
except Exception as e:
|
||||
|
|
|
@ -102,6 +102,11 @@ static bool read_wav(const std::string & b64data, std::vector<float>& pcmf32, st
|
|||
std::vector<float> raw_pcm;
|
||||
raw_pcm.resize(n);
|
||||
|
||||
if(whisperdebugmode==1)
|
||||
{
|
||||
printf("\nwav_data_size: %d, n:%d",wav_data.size(),n);
|
||||
}
|
||||
|
||||
// convert to mono, float
|
||||
if (wav.channels == 1) {
|
||||
for (uint64_t i = 0; i < n; i++) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue