feat: Ajout d'un service de synthèse vocale hybride et intégration de Google Cloud TTS
This commit is contained in:
@@ -16,6 +16,7 @@ const { Storage } = require('@google-cloud/storage');
|
||||
// Utilitaires
|
||||
const auth = require('./utils/auth');
|
||||
const helpers = require('./utils/helpers');
|
||||
const { generateTTS } = require('./generateTTS');
|
||||
|
||||
// Initialisation sécurisée
|
||||
if (!admin.apps.length) {
|
||||
@@ -4193,3 +4194,72 @@ exports.quickSearch = onRequest(httpOptions, withCors(async (req, res) => {
|
||||
res.status(500).json({ error: error.message });
|
||||
}
|
||||
}));
|
||||
|
||||
// ============================================================================
|
||||
// TEXT-TO-SPEECH - Generate TTS Audio
|
||||
// ============================================================================
|
||||
// Options HTTP spécifiques pour TTS avec CORS activé
|
||||
const ttsHttpOptions = {
|
||||
cors: true, // Activer CORS automatique
|
||||
invoker: 'public',
|
||||
region: 'europe-west9',
|
||||
};
|
||||
|
||||
exports.generateTTSV2 = onRequest(ttsHttpOptions, async (req, res) => {
|
||||
try {
|
||||
// Authentification utilisateur
|
||||
const decodedToken = await auth.authenticateUser(req);
|
||||
|
||||
logger.info('[generateTTSV2] Request from user:', {
|
||||
uid: decodedToken.uid,
|
||||
email: decodedToken.email,
|
||||
});
|
||||
|
||||
// Récupération des paramètres
|
||||
const { text, voiceConfig } = req.body.data || {};
|
||||
|
||||
// Validation
|
||||
if (!text) {
|
||||
res.status(400).json({ error: 'Text parameter is required' });
|
||||
return;
|
||||
}
|
||||
|
||||
if (text.length > 5000) {
|
||||
res.status(400).json({ error: 'Text too long (max 5000 characters)' });
|
||||
return;
|
||||
}
|
||||
|
||||
// Génération de l'audio avec cache
|
||||
const bucketName = admin.storage().bucket().name;
|
||||
const bucket = storage.bucket(bucketName);
|
||||
|
||||
const result = await generateTTS(text, storage, bucket, voiceConfig);
|
||||
|
||||
logger.info('[generateTTSV2] ✓ Success', {
|
||||
cached: result.cached,
|
||||
cacheKey: result.cacheKey,
|
||||
});
|
||||
|
||||
res.status(200).json({
|
||||
audioUrl: result.audioUrl,
|
||||
cached: result.cached,
|
||||
cacheKey: result.cacheKey,
|
||||
});
|
||||
|
||||
} catch (error) {
|
||||
logger.error('[generateTTSV2] ✗ Error:', {
|
||||
error: error.message,
|
||||
code: error.code,
|
||||
});
|
||||
|
||||
// Gestion des erreurs spécifiques
|
||||
if (error.code === 'PERMISSION_DENIED') {
|
||||
res.status(403).json({ error: 'Permission denied. Check Google Cloud TTS API is enabled.' });
|
||||
} else if (error.code === 'QUOTA_EXCEEDED') {
|
||||
res.status(429).json({ error: 'TTS quota exceeded. Try again later.' });
|
||||
} else {
|
||||
res.status(500).json({ error: error.message });
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user