mirror of
https://github.com/open-webui/open-webui
synced 2025-02-11 15:33:38 +00:00
refac: audio input (audio/ogg support)
This commit is contained in:
parent
0b30dc357c
commit
62f1933e3c
@ -309,7 +309,7 @@ def transcribe(
|
|||||||
):
|
):
|
||||||
log.info(f"file.content_type: {file.content_type}")
|
log.info(f"file.content_type: {file.content_type}")
|
||||||
|
|
||||||
if file.content_type not in ["audio/mpeg", "audio/wav"]:
|
if file.content_type not in ["audio/mpeg", "audio/wav", "audio/ogg"]:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=status.HTTP_400_BAD_REQUEST,
|
status_code=status.HTTP_400_BAD_REQUEST,
|
||||||
detail=ERROR_MESSAGES.FILE_NOT_SUPPORTED,
|
detail=ERROR_MESSAGES.FILE_NOT_SUPPORTED,
|
||||||
|
@ -93,20 +93,6 @@
|
|||||||
const uploadFileHandler = async (file) => {
|
const uploadFileHandler = async (file) => {
|
||||||
console.log(file);
|
console.log(file);
|
||||||
|
|
||||||
// Check if the file is an audio file and transcribe/convert it to text file
|
|
||||||
if (['audio/mpeg', 'audio/wav'].includes(file['type'])) {
|
|
||||||
const res = await transcribeAudio(localStorage.token, file).catch((error) => {
|
|
||||||
toast.error(error);
|
|
||||||
return null;
|
|
||||||
});
|
|
||||||
|
|
||||||
if (res) {
|
|
||||||
console.log(res);
|
|
||||||
const blob = new Blob([res.text], { type: 'text/plain' });
|
|
||||||
file = blobToFile(blob, `${file.name}.txt`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const fileItem = {
|
const fileItem = {
|
||||||
type: 'file',
|
type: 'file',
|
||||||
file: '',
|
file: '',
|
||||||
@ -120,6 +106,23 @@
|
|||||||
};
|
};
|
||||||
files = [...files, fileItem];
|
files = [...files, fileItem];
|
||||||
|
|
||||||
|
// Check if the file is an audio file and transcribe/convert it to text file
|
||||||
|
if (['audio/mpeg', 'audio/wav', 'audio/ogg'].includes(file['type'])) {
|
||||||
|
const res = await transcribeAudio(localStorage.token, file).catch((error) => {
|
||||||
|
toast.error(error);
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (res) {
|
||||||
|
console.log(res);
|
||||||
|
const blob = new Blob([res.text], { type: 'text/plain' });
|
||||||
|
file = blobToFile(blob, `${file.name}.txt`);
|
||||||
|
|
||||||
|
fileItem.name = file.name;
|
||||||
|
fileItem.size = file.size;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const uploadedFile = await uploadFile(localStorage.token, file);
|
const uploadedFile = await uploadFile(localStorage.token, file);
|
||||||
|
|
||||||
|
@ -55,7 +55,7 @@
|
|||||||
const uploadDoc = async (file, tags?: object) => {
|
const uploadDoc = async (file, tags?: object) => {
|
||||||
console.log(file);
|
console.log(file);
|
||||||
// Check if the file is an audio file and transcribe/convert it to text file
|
// Check if the file is an audio file and transcribe/convert it to text file
|
||||||
if (['audio/mpeg', 'audio/wav'].includes(file['type'])) {
|
if (['audio/mpeg', 'audio/wav', 'audio/ogg'].includes(file['type'])) {
|
||||||
const transcribeRes = await transcribeAudio(localStorage.token, file).catch((error) => {
|
const transcribeRes = await transcribeAudio(localStorage.token, file).catch((error) => {
|
||||||
toast.error(error);
|
toast.error(error);
|
||||||
return null;
|
return null;
|
||||||
|
Loading…
Reference in New Issue
Block a user