This commit is contained in:
zyronon
2023-11-09 15:55:06 +08:00
parent 76269c50fe
commit 3c60cf521b
7 changed files with 98 additions and 43 deletions

View File

@@ -23,11 +23,13 @@ export function useSound(audioSrcList?: string[], audioFileLength?: number) {
index = 0
}
function play() {
function play(volume: number = 100) {
index++
if (audioList.length > 1 && audioList.length !== audioLength) {
audioList[index % audioList.length].volume = volume / 100
audioList[index % audioList.length].play()
} else {
audioList[index % audioLength].volume = volume / 100
audioList[index % audioLength].play()
}
}
@@ -35,6 +37,7 @@ export function useSound(audioSrcList?: string[], audioFileLength?: number) {
return {play, setAudio}
}
export function usePlayKeyboardAudio() {
const settingStore = useSettingStore()
const {play, setAudio} = useSound()
@@ -46,7 +49,7 @@ export function usePlayKeyboardAudio() {
function playAudio() {
if (settingStore.keyboardSound) {
play()
play(settingStore.keyboardSoundVolume)
}
}
@@ -59,7 +62,7 @@ export function usePlayBeep() {
function playAudio() {
if (settingStore.effectSound) {
play()
play(settingStore.effectSoundVolume)
}
}
@@ -72,7 +75,7 @@ export function usePlayCorrect() {
function playAudio() {
if (settingStore.effectSound) {
play()
play(settingStore.effectSoundVolume)
}
}
@@ -89,6 +92,8 @@ export function usePlayWordAudio() {
} else if (settingStore.wordSoundType === 'us') {
audio.src = `${PronunciationApi}${word}&type=2`
}
audio.volume = settingStore.wordSoundVolume / 100
audio.playbackRate = settingStore.wordSoundSpeed
audio.play()
}
@@ -111,14 +116,13 @@ export function useTTsPlayAudio() {
msg.lang = 'zh-CN';
isPlay = true
window.speechSynthesis.speak(msg);
console.log('text',text)
console.log('text', text)
}
return play
}
export function usePlayAudio(url: string) {
new Audio(url).play().then(r => void 0)
}