Skip to content

Commit

Permalink
feat: add download button for voice search page
Browse files Browse the repository at this point in the history
  • Loading branch information
darwintree committed Feb 21, 2024
1 parent 538a71e commit e2928be
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 2024/02/22

* feat: add download button for voice search page

## 2024/02/21

* feat: support anim filter for voice search
Expand Down
2 changes: 2 additions & 0 deletions src/components/search/VoiceSearchPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ const createColumns = (): any => {
return h(AudioLabel, {
...extractAudioLabelPropFromVoiceId(row._id),
extraText: row.speaker,
displayDownload: true,
audioText: row.text,
})
},
align: 'center',
Expand Down
51 changes: 48 additions & 3 deletions src/components/translate/AudioLabel.vue
Original file line number Diff line number Diff line change
@@ -1,18 +1,28 @@
<template>
<label
v-if="hasAudio"
class="audio-button"
class="audio-button clickable"
:title="audioTitle"
@click="playAudio"
>{{ extraText }} {{ audioIcon }}</label
>

<n-icon v-if="displayDownload" class="clickable" @click="downloadAudio">
<Download />
</n-icon>
</template>
<script lang="ts">
import { defineComponent } from 'vue'
import { NIcon } from 'naive-ui'
import { Download } from '@vicons/carbon'
import { getAudioPath } from '../../helper/path'
// define the props for the component
export default defineComponent({
components: {
NIcon,
Download,
},
props: {
// the audio file URL
id: {
Expand All @@ -23,12 +33,24 @@ export default defineComponent({
type: String,
required: true,
},
// the label text to display next to the audio button
extraText: {
type: String,
required: false,
default: '',
},
// the label text to display next to the audio button
// use to change downlownded filename
// not in use at present
audioText: {
type: String,
required: false,
default: '',
},
displayDownload: {
type: Boolean,
required: false,
default: false,
},
},
data() {
return {
Expand All @@ -54,6 +76,9 @@ export default defineComponent({
},
},
methods: {
getBaseName(filePath: string) {
return filePath.split('/').pop()
},
// define the "playAudio" function to play the audio file
playAudio() {
// create a new Audio object with the audio URL
Expand All @@ -72,16 +97,36 @@ export default defineComponent({
// update the audio button title to indicate that the audio is playing
this.isPlaying = true
},
downloadAudio() {
// download the audio file
window.open(this.audioUrl, '_blank')
// const request = new XMLHttpRequest()
// request.open('GET', this.audioUrl, true)
// request.responseType = 'blob'
// request.onload = (e) => {
// if (request.readyState === 4 && request.status === 200) {
// const blob = new Blob([request.response], { type: 'audio/wav' })
// saveAs(
// blob,
// this.audioText ? this.audioText : this.getBaseName(this.audioUrl)
// )
// }
// }
// request.send()
},
},
})
</script>
<style scoped>
/* define the layout and styling for the "AudioLabel" component */
.clickable {
cursor: pointer;
}
.audio-button {
background: transparent;
border: none;
cursor: pointer;
font-size: 1em;
}
</style>

0 comments on commit e2928be

Please sign in to comment.