File tree Expand file tree Collapse file tree 2 files changed +12
-5
lines changed
Expand file tree Collapse file tree 2 files changed +12
-5
lines changed Original file line number Diff line number Diff line change @@ -80,8 +80,8 @@ async function generateContent(
8080 }
8181
8282 const session = await ai . live . connect ( {
83- model,
84- config,
83+ model : modelId ,
84+ config : config ,
8585 callbacks : {
8686 onmessage : msg => responseQueue . push ( msg ) ,
8787 onerror : e => console . error ( 'Error:' , e . message ) ,
@@ -98,11 +98,18 @@ async function generateContent(
9898 const audioChunks = await handleTurn ( session ) ;
9999
100100 session . close ( ) ;
101- return turns ;
101+
102+ if ( audioChunks . length > 0 ) {
103+ const audioBuffer = Buffer . concat ( audioChunks ) ;
104+ fs . writeFileSync ( 'response.raw' , audioBuffer ) ;
105+ console . log ( 'Received audio answer (saved to response.raw)' ) ;
106+ }
107+
108+ return audioChunks ;
102109}
103110// Example output:
104111//> Hello? Gemini, are you there?
105- // Yes, I'm here. What would you like to talk about?
112+ // Received audio answer (saved to response.raw)
106113// [END googlegenaisdk_live_audio_with_txt]
107114
108115module . exports = {
Original file line number Diff line number Diff line change @@ -21,7 +21,7 @@ const projectId = process.env.CAIP_PROJECT_ID;
2121const sample = require ( '../live/live-audio-with-txt' ) ;
2222
2323describe ( 'live-audio-with-txt' , ( ) => {
24- it ( 'should generate text content from a text prompt and multiple images ' , async function ( ) {
24+ it ( 'should generate audio content from a text prompt' , async function ( ) {
2525 this . timeout ( 180000 ) ;
2626 const output = await sample . generateContent ( projectId ) ;
2727 console . log ( 'Generated output:' , output ) ;
You can’t perform that action at this time.
0 commit comments