Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
闫辉
VueJS_637753
提交
34acb82a
V
VueJS_637753
项目概览
闫辉
/
VueJS_637753
与 Fork 源项目一致
Fork自
inscode / VueJS
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
VueJS_637753
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
34acb82a
编写于
9月 12, 2024
作者:
S
superyan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Thu Sep 12 10:41:00 CST 2024 inscode
上级
6c64dffa
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
216 addition
and
20 deletion
+216
-20
package.json
package.json
+2
-0
src/App.vue
src/App.vue
+214
-20
未找到文件。
package.json
浏览文件 @
34acb82a
...
...
@@ -7,7 +7,9 @@
"preview"
:
"vite preview --port 4173"
},
"dependencies"
:
{
"
aonweb
"
:
"
^2.0.2
"
,
"
guess
"
:
"
^1.0.2
"
,
"
vant
"
:
"
^4.9.5
"
,
"
vue
"
:
"
^3.2.37
"
},
"devDependencies"
:
{
...
...
src/App.vue
浏览文件 @
34acb82a
<
template
>
<div
id=
"app"
>
<SearchPage
v-if=
"currentPage === 'search'"
@
search=
"handleSearch"
/>
<ResultsPage
v-else
:searchQuery=
"searchQuery"
@
back=
"goToSearch"
/>
<h1>
User Account Information
</h1>
<div
v-if=
"loadingAccount"
>
Loading account information, please wait...
</div>
<div
v-else
>
<p
v-if=
"account"
>
Account:
{{
account
}}
</p>
<p
v-if=
"points !== null"
>
Remaining Points:
{{
points
}}
</p>
</div>
<div
v-if=
"error"
>
{{
error
}}
</div>
<h1>
Whisper API - Automatic Speech Recognition
</h1>
<!-- 添加文件上传输入框 -->
<input
type=
"file"
id=
"fileInput"
@
change=
"handleFileChange"
accept=
"audio/*"
/>
<!-- 上传按钮 -->
<button
type=
"button"
@
click=
"handleFileUpload"
:disabled=
"!selectedFile"
>
Upload Audio
</button>
<form
@
submit.prevent=
"performASR"
>
<div>
<label
for=
"awv"
>
Audio URL:
</label>
<input
v-model=
"inputData.audio"
type=
"text"
id=
"awv"
placeholder=
"Enter audio file URL"
required
readonly
>
</div>
<div>
<label
for=
"model"
>
Model:
</label>
<input
v-model=
"inputData.model"
type=
"text"
id=
"model"
placeholder=
"Enter model"
required
>
</div>
<div>
<label
for=
"translate"
>
Translate:
</label>
<input
type=
"checkbox"
v-model=
"inputData.translate"
id=
"translate"
>
</div>
<div>
<label
for=
"temperature"
>
Temperature:
</label>
<input
v-model.number=
"inputData.temperature"
type=
"number"
id=
"temperature"
required
>
</div>
<button
type=
"button"
@
click=
"performASR"
:disabled=
"!inputData.audio"
>
Perform ASR
</button>
</form>
<div
v-if=
"loading"
>
Processing audio, please wait...
</div>
<div
v-if=
"error"
>
{{
error
}}
</div>
<div
v-if=
"recognizedText"
>
<h2>
Recognized Text:
</h2>
<p>
{{
recognizedText
}}
</p>
</div>
<!-- 显示上传后的 JSON 数据 -->
<div
v-if=
"uploadResponse"
>
<h2>
Upload Response:
</h2>
<pre>
{{
uploadResponse
}}
</pre>
</div>
<!-- 显示 Perform ASR 返回的 JSON 数据 -->
<div
v-if=
"asrResponse"
>
<h2>
ASR Response:
</h2>
<pre>
{{
asrResponse
}}
</pre>
</div>
</div>
</
template
>
<
script
>
import
SearchPage
from
'
./components/SearchPage.vue
'
;
import
ResultsPage
from
'
./components/ResultsPage.vue
'
;
import
{
AI
,
AIOptions
,
User
,
detectEthereumProvider
}
from
'
aonweb
'
;
import
{
showToast
,
showLoadingToast
,
closeToast
}
from
'
vant
'
;
export
default
{
name
:
'
App
'
,
components
:
{
SearchPage
,
ResultsPage
},
data
()
{
return
{
currentPage
:
'
search
'
,
searchQuery
:
''
account
:
null
,
points
:
null
,
loadingAccount
:
false
,
inputData
:
{
audio
:
''
,
// 自动填充上传后的音频URL
model
:
'
large-v3
'
,
translate
:
false
,
temperature
:
0
,
transcription
:
'
plain text
'
,
suppress_tokens
:
'
-1
'
,
logprob_threshold
:
-
1
,
no_speech_threshold
:
0.6
,
condition_on_previous_text
:
true
,
compression_ratio_threshold
:
2.4
,
temperature_increment_on_fallback
:
0.2
},
selectedFile
:
null
,
// 用于保存选择的文件
recognizedText
:
null
,
loading
:
false
,
error
:
null
,
uploadResponse
:
null
,
// 用于保存上传后的JSON响应
asrResponse
:
null
,
// 用于保存ASR返回的JSON响应
};
},
methods
:
{
handleSearch
(
query
)
{
this
.
searchQuery
=
query
;
this
.
currentPage
=
'
results
'
;
async
getAccount
()
{
this
.
loadingAccount
=
true
;
this
.
error
=
null
;
try
{
let
user
=
new
User
();
const
isLoginStatus
=
await
user
.
islogin
();
console
.
log
(
isLoginStatus
,
'
isLoginStatus
'
);
if
(
!
isLoginStatus
)
{
showLoadingToast
({
duration
:
0
,
forbidClick
:
true
,
message
:
'
Loading...
'
,
});
user
.
login
(
async
(
acc
,
userId
,
error
)
=>
{
closeToast
();
if
(
error
)
{
this
.
error
=
`Login error:
${
error
.
message
||
error
}
`
;
return
;
}
this
.
account
=
acc
;
bus
.
emit
(
'
get_balance
'
,
"
login
"
);
await
this
.
getBalance
();
// 获取剩余积分
});
}
else
{
this
.
account
=
await
user
.
getAccount
();
console
.
log
(
"
getWeb3 account
"
,
this
.
account
);
let
userId
=
await
user
.
getUserId
();
console
.
log
(
"
getWeb3 userId
"
,
userId
);
bus
.
emit
(
'
get_balance
'
,
"
login
"
);
await
this
.
getBalance
();
// 获取剩余积分
}
}
catch
(
error
)
{
this
.
error
=
`Error retrieving account:
${
error
.
message
||
error
}
`
;
}
finally
{
this
.
loadingAccount
=
false
;
}
},
goToSearch
()
{
this
.
currentPage
=
'
search
'
;
async
getBalance
()
{
try
{
let
user
=
new
User
();
this
.
points
=
await
user
.
getPoints
();
}
catch
(
error
)
{
this
.
error
=
`Error retrieving points:
${
error
.
message
||
error
}
`
;
}
},
handleFileChange
(
event
)
{
this
.
selectedFile
=
event
.
target
.
files
[
0
];
if
(
this
.
selectedFile
.
size
>
30
*
1024
*
1024
)
{
this
.
onOversize
(
this
.
selectedFile
);
}
},
handleFileUpload
()
{
if
(
this
.
selectedFile
)
{
this
.
afterRead
({
file
:
this
.
selectedFile
});
}
},
onOversize
(
file
)
{
alert
(
'
The file size cannot exceed 30MB
'
);
},
async
afterRead
(
file
)
{
const
formData
=
new
FormData
();
formData
.
append
(
'
file
'
,
file
.
file
);
try
{
const
res
=
await
this
.
uploadFile
(
formData
);
this
.
uploadResponse
=
res
;
// 保存上传后的JSON响应
if
(
res
.
code
===
200
&&
res
.
data
)
{
this
.
inputData
.
audio
=
res
.
data
;
// 将返回的 data 字段的值填充到 audio URL 的输入框中
}
}
catch
(
err
)
{
alert
(
'
Audio upload failed
'
);
console
.
log
(
err
);
}
},
async
uploadFile
(
formData
)
{
const
response
=
await
fetch
(
'
https://tmp-file.aigic.ai/api/v1/upload?expires=1800&type=audio/mp3
'
,
{
method
:
'
POST
'
,
body
:
formData
});
const
data
=
await
response
.
json
();
return
data
;
},
async
performASR
()
{
this
.
loading
=
true
;
this
.
error
=
null
;
this
.
recognizedText
=
null
;
const
aiOptions
=
new
AIOptions
({
appId
:
'
1pJL7vKQKgU33yqmo6ACfFAh.CoI1HkbwcujTEe.pt0A
'
,
dev_mode
:
true
});
const
aonweb
=
new
AI
(
aiOptions
);
try
{
const
price
=
8
;
const
response
=
await
aonweb
.
prediction
(
"
/predictions/ai/whisper
"
,
{
input
:
this
.
inputData
},
price
);
this
.
asrResponse
=
response
;
// 保存 ASR 返回的 JSON 响应
this
.
recognizedText
=
response
.
data
.
result
;
// 假设返回的识别结果在 `result` 字段中
}
catch
(
err
)
{
this
.
error
=
'
Error performing ASR:
'
+
err
.
message
;
}
finally
{
this
.
loading
=
false
;
}
},
},
mounted
()
{
this
.
getAccount
();
}
};
</
script
>
<
style
>
<
style
scoped
>
#app
{
font-family
:
Arial
,
sans-serif
;
font-family
:
Avenir
,
Helvetica
,
Arial
,
sans-serif
;
text-align
:
center
;
margin-top
:
60px
;
}
form
div
{
margin-bottom
:
20px
;
}
button
{
padding
:
10px
20px
;
background-color
:
#42b983
;
color
:
white
;
border
:
none
;
border-radius
:
5px
;
cursor
:
pointer
;
}
button
:hover
{
background-color
:
#369b74
;
}
</
style
>
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录