jbilcke-hf HF staff commited on
Commit
f21588d
1 Parent(s): 2eea766

add the wav header

Browse files
src/app/api/generators/speech/generateVoiceWithParlerTTS.ts CHANGED
@@ -52,13 +52,22 @@ export async function generateSpeechWithParlerTTS({
52
  throw new Error('Failed to fetch data')
53
  }
54
 
55
- const rawJson = await res.json()
56
-
57
- console.log("rawJson:", rawJson)
58
 
59
- // TODO: addBAse64 with the right header type
60
-
61
- return ""
 
 
 
 
 
 
 
 
 
 
62
  }
63
 
64
  try {
@@ -72,6 +81,7 @@ export async function generateSpeechWithParlerTTS({
72
  debug,
73
  failureMessage: "failed to generate the audio"
74
  })
 
75
  return result
76
  } catch (err) {
77
  if (neverThrow) {
 
52
  throw new Error('Failed to fetch data')
53
  }
54
 
55
+
56
+ const { data } = await res.json()
 
57
 
58
+ // console.log("data:", data)
59
+ // Recommendation: handle errors
60
+ if (res.status !== 200 || !Array.isArray(data)) {
61
+ // This will activate the closest `error.js` Error Boundary
62
+ throw new Error(`Failed to fetch data (status: ${res.status})`)
63
+ }
64
+ // console.log("data:", data.slice(0, 50))
65
+
66
+ if (!data[0]) {
67
+ throw new Error(`the returned audio was empty`)
68
+ }
69
+
70
+ return addBase64Header(data[0] as string, "wav")
71
  }
72
 
73
  try {
 
81
  debug,
82
  failureMessage: "failed to generate the audio"
83
  })
84
+
85
  return result
86
  } catch (err) {
87
  if (neverThrow) {