11import express from 'express' ;
22import { ImageGenerationHandler } from './imageGeneration' ;
33import { ChatHandler } from './chatHandler' ;
4+ import { AudioGenerationHandler } from './audioGeneration' ;
45
56const app = express ( ) ;
67const imageHandler = new ImageGenerationHandler ( ) ;
78const chatHandler = new ChatHandler ( ) ;
9+ const audioHandler = new AudioGenerationHandler ( ) ;
810
911app . use ( express . json ( { limit : '25mb' } ) ) ;
1012
@@ -20,7 +22,12 @@ app.use((req, res, next) => {
2022app . post ( '/reset' , ( req , res ) => {
2123 imageHandler . reset ( ) ;
2224 chatHandler . reset ( ) ;
23- res . status ( 200 ) . json ( { status : 'ok' , message : 'Image counter reset to 0' } ) ;
25+ audioHandler . reset ( ) ;
26+ res . status ( 200 ) . json ( { status : 'ok' , message : 'Mock state reset' } ) ;
27+ } ) ;
28+
29+ app . get ( '/stats' , ( req , res ) => {
30+ res . status ( 200 ) . json ( { audioCallCount : audioHandler . getCallCount ( ) } ) ;
2431} ) ;
2532
2633app . post ( '/configure' , ( req , res ) => {
@@ -60,6 +67,38 @@ app.post(
6067 }
6168) ;
6269
70+ app . post (
71+ '/v1beta/models/gemini-3.1-flash-tts-preview:generateContent' ,
72+ ( req , res ) => {
73+ try {
74+ const prompt = req . body . contents [ 0 ] . parts [ 0 ] . text ;
75+ const voiceName =
76+ req . body . generationConfig ?. speechConfig ?. voiceConfig
77+ ?. prebuiltVoiceConfig ?. voiceName ;
78+ const audio = audioHandler . generateAudio ( prompt , voiceName ) ;
79+ res . status ( 200 ) . json ( {
80+ candidates : [
81+ {
82+ content : {
83+ parts : [
84+ {
85+ inlineData : {
86+ mimeType : 'audio/L16;codec=pcm;rate=24000' ,
87+ data : audio ,
88+ } ,
89+ } ,
90+ ] ,
91+ } ,
92+ } ,
93+ ] ,
94+ } ) ;
95+ } catch ( error ) {
96+ console . error ( 'Audio generation error:' , error ) ;
97+ res . status ( 500 ) . json ( { error : { message : 'Audio generation failed' } } ) ;
98+ }
99+ }
100+ ) ;
101+
63102app . post ( / \/ v 1 b e t a \/ m o d e l s \/ ( [ ^ / ] + ) : g e n e r a t e C o n t e n t / , async ( req , res ) => {
64103 try {
65104 const model = req . params [ 0 ] ;
0 commit comments