@@ -203,17 +203,9 @@ recipeButtons.forEach((button) => {
203203
204204 ///
205205
206- const audio_data = createAudio ( data . audio ) ;
207- await cacheData ( audio_data , CACHE_NAME_AUDIO , "audio" ) ;
208- displayElementsFlex ( [ recording ] ) ;
209- displayElements ( [ sendRecipeToUserInboxBtn , userWantAnotherRecipe ] ) ;
210- const speechBtns = Array . from ( document . querySelectorAll ( ".fa-solid" ) ) ;
211- const speedBtn = document . querySelector ( "#speed" ) ;
212- audioElement . src = createAudio ( data . audio ) ;
213- audioElement . stop = function ( ) {
214- this . pause ( ) ;
215- this . currentTime = 0 ;
216- } ;
206+ // const audio_data = createAudio(data.audio);
207+ // await cacheData(audio_data, CACHE_NAME_AUDIO, "audio");
208+ const { speedBtn, speechBtns } = createTextToSpeech ( data ) ;
217209
218210 userWantAnotherRecipe . addEventListener ( "click" , ( ) => {
219211 displayElements ( [ headline , allergies , ...recipeButtons , mainElement ] ) ;
@@ -246,6 +238,19 @@ recipeButtons.forEach((button) => {
246238 } ) ;
247239} ) ;
248240
241+ function createTextToSpeech ( param ) {
242+ displayElementsFlex ( [ recording ] ) ;
243+ displayElements ( [ sendRecipeToUserInboxBtn , userWantAnotherRecipe ] ) ;
244+ const speechBtns = Array . from ( document . querySelectorAll ( ".fa-solid" ) ) ;
245+ const speedBtn = document . querySelector ( "#speed" ) ;
246+ audioElement . src = createAudio ( param . audio ) ;
247+ audioElement . stop = function ( ) {
248+ this . pause ( ) ;
249+ this . currentTime = 0 ;
250+ } ;
251+ return { speedBtn, speechBtns } ;
252+ }
253+
249254// Picture section
250255async function getVideoDevices ( ) {
251256 const devices = await navigator . mediaDevices . enumerateDevices ( ) ;
0 commit comments