Skip to content

Commit

Permalink
axios blob (#405)
Browse files Browse the repository at this point in the history
* axios blob

* update
  • Loading branch information
swuecho authored Dec 10, 2023
1 parent 5a6c49c commit 6527e0a
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions web/src/views/chat/components/AudioPlayer/index.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<script lang="ts" setup>
import { ref } from "vue";
import { HoverButton, SvgIcon } from '@/components/common'
import request from '@/utils/request/axios'
interface Props {
text: string
Expand All @@ -14,7 +15,9 @@ const isActive = ref(false);
// const speaker_id = ref('')
// const style_wav = ref('')
// const language_id = ref('')
const BASE_URL = import.meta.env.VITE_GLOB_API_URL
// Add a method called 'playAudio' to handle sending the request to the backend.
Expand All @@ -26,11 +29,11 @@ async function playAudio() {
let text = encodeURIComponent(props.text)
try {
// Perform the HTTP request to send the request to the backend.
const response = await fetch(`${BASE_URL}/tts?text=${text}`,
{ cache: 'no-cache' });
if (response.ok) {
const response = await request.get(`/tts?text=${text}`, { responseType: 'blob' });
console.log(response)
if (response.status == 200) {
// If the HTTP response is successful, parse the body into an object and play the sound.
const blob = await response.blob();
const blob = await response.data;
source.value = URL.createObjectURL(blob);
console.log(source.value);
isActive.value = true;
Expand Down

0 comments on commit 6527e0a

Please sign in to comment.