Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
open-webui
Commits
4a73a01c
Commit
4a73a01c
authored
Jun 06, 2024
by
Timothy J. Baek
Browse files
refac
parent
1a9dee50
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
33 additions
and
26 deletions
+33
-26
backend/apps/audio/main.py
backend/apps/audio/main.py
+15
-3
src/lib/components/chat/MessageInput.svelte
src/lib/components/chat/MessageInput.svelte
+15
-2
src/lib/components/chat/Settings/Audio.svelte
src/lib/components/chat/Settings/Audio.svelte
+3
-21
No files found.
backend/apps/audio/main.py
View file @
4a73a01c
...
@@ -17,7 +17,7 @@ from fastapi.middleware.cors import CORSMiddleware
...
@@ -17,7 +17,7 @@ from fastapi.middleware.cors import CORSMiddleware
from
faster_whisper
import
WhisperModel
from
faster_whisper
import
WhisperModel
from
pydantic
import
BaseModel
from
pydantic
import
BaseModel
import
uuid
import
requests
import
requests
import
hashlib
import
hashlib
from
pathlib
import
Path
from
pathlib
import
Path
...
@@ -181,8 +181,15 @@ def transcribe(
...
@@ -181,8 +181,15 @@ def transcribe(
)
)
try
:
try
:
filename
=
file
.
filename
ext
=
file
.
filename
.
split
(
"."
)[
-
1
]
file_path
=
f
"
{
UPLOAD_DIR
}
/
{
filename
}
"
id
=
uuid
.
uuid4
()
filename
=
f
"
{
id
}
.
{
ext
}
"
file_dir
=
f
"
{
CACHE_DIR
}
/audio/transcriptions"
os
.
makedirs
(
file_dir
,
exist_ok
=
True
)
file_path
=
f
"
{
file_dir
}
/
{
filename
}
"
contents
=
file
.
file
.
read
()
contents
=
file
.
file
.
read
()
with
open
(
file_path
,
"wb"
)
as
f
:
with
open
(
file_path
,
"wb"
)
as
f
:
f
.
write
(
contents
)
f
.
write
(
contents
)
...
@@ -215,6 +222,11 @@ def transcribe(
...
@@ -215,6 +222,11 @@ def transcribe(
transcript
=
""
.
join
([
segment
.
text
for
segment
in
list
(
segments
)])
transcript
=
""
.
join
([
segment
.
text
for
segment
in
list
(
segments
)])
# save the transcript to a json file
transcript_file
=
f
"
{
file_dir
}
/
{
id
}
.json"
with
open
(
transcript_file
,
"w"
)
as
f
:
json
.
dump
({
"transcript"
:
transcript
},
f
)
return
{
"text"
:
transcript
.
strip
()}
return
{
"text"
:
transcript
.
strip
()}
except
Exception
as
e
:
except
Exception
as
e
:
...
...
src/lib/components/chat/MessageInput.svelte
View file @
4a73a01c
...
@@ -842,8 +842,21 @@
...
@@ -842,8 +842,21 @@
id="voice-input-button"
id="voice-input-button"
class=" text-gray-600 dark:text-gray-300 hover:bg-gray-50 dark:hover:bg-gray-850 transition rounded-full p-1.5 mr-0.5 self-center"
class=" text-gray-600 dark:text-gray-300 hover:bg-gray-50 dark:hover:bg-gray-850 transition rounded-full p-1.5 mr-0.5 self-center"
type="button"
type="button"
on:click={() => {
on:click={async () => {
recording = true;
const res = await navigator.mediaDevices
.getUserMedia({ audio: true })
.catch(function (err) {
toast.error(
$i18n.t(`Permission denied when accessing microphone: {{error}}`, {
error: err
})
);
return null;
});
if (res) {
recording = true;
}
}}
}}
>
>
<svg
<svg
...
...
src/lib/components/chat/Settings/Audio.svelte
View file @
4a73a01c
...
@@ -168,7 +168,7 @@
...
@@ -168,7 +168,7 @@
<
select
<
select
class
=
"dark:bg-gray-900 w-fit pr-8 rounded px-2 p-1 text-xs bg-transparent outline-none text-right"
class
=
"dark:bg-gray-900 w-fit pr-8 rounded px-2 p-1 text-xs bg-transparent outline-none text-right"
bind
:
value
={
STTEngine
}
bind
:
value
={
STTEngine
}
placeholder
=
"Select a
mod
e"
placeholder
=
"Select a
n engin
e"
on
:
change
={(
e
)
=>
{
on
:
change
={(
e
)
=>
{
if
(
e
.
target
.
value
!== '') {
if
(
e
.
target
.
value
!== '') {
navigator
.
mediaDevices
.
getUserMedia
({
audio
:
true
}).
catch
(
function
(
err
)
{
navigator
.
mediaDevices
.
getUserMedia
({
audio
:
true
}).
catch
(
function
(
err
)
{
...
@@ -182,30 +182,12 @@
...
@@ -182,30 +182,12 @@
}
}
}}
}}
>
>
<
option
value
=
""
>{$
i18n
.
t
(
'Default (W
eb API
)'
)}</
option
>
<
option
value
=
""
>{$
i18n
.
t
(
'Default (W
hisper
)'
)}</
option
>
<
option
value
=
"w
hisper-local
"
>{$
i18n
.
t
(
'W
hisper (Local)
'
)}</
option
>
<
option
value
=
"w
eb
"
>{$
i18n
.
t
(
'W
eb API
'
)}</
option
>
</
select
>
</
select
>
</
div
>
</
div
>
</
div
>
</
div
>
<
div
class
=
" py-0.5 flex w-full justify-between"
>
<
div
class
=
" self-center text-xs font-medium"
>{$
i18n
.
t
(
'Conversation Mode'
)}</
div
>
<
button
class
=
"p-1 px-3 text-xs flex rounded transition"
on
:
click
={()
=>
{
toggleConversationMode
();
}}
type
=
"button"
>
{#
if
conversationMode
===
true
}
<
span
class
=
"ml-2 self-center"
>{$
i18n
.
t
(
'On'
)}</
span
>
{:
else
}
<
span
class
=
"ml-2 self-center"
>{$
i18n
.
t
(
'Off'
)}</
span
>
{/
if
}
</
button
>
</
div
>
<
div
class
=
" py-0.5 flex w-full justify-between"
>
<
div
class
=
" py-0.5 flex w-full justify-between"
>
<
div
class
=
" self-center text-xs font-medium"
>
<
div
class
=
" self-center text-xs font-medium"
>
{$
i18n
.
t
(
'Auto-send input after 3 sec.'
)}
{$
i18n
.
t
(
'Auto-send input after 3 sec.'
)}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment