askhjdgkjasghdfjahs
This commit is contained in:
107
gemini.js
Normal file
107
gemini.js
Normal file
@@ -0,0 +1,107 @@
|
||||
import { GoogleGenAI, createUserContent, createPartFromUri } from "@google/genai";
|
||||
import dotenv from "dotenv";
|
||||
dotenv.config();
|
||||
|
||||
import wav from 'wav';
|
||||
|
||||
|
||||
// The client gets the API key from the environment variable `GEMINI_API_KEY`.
|
||||
const ai = new GoogleGenAI({apiKey: process.env.GEMINI_KEY});
|
||||
|
||||
const AUDIO_URL = "https://s3.twcstorage.ru/22b2a814-mhand/audio_2026-01-28_12-59-38.ogg"
|
||||
|
||||
async function saveWaveFile(
|
||||
filename,
|
||||
pcmData,
|
||||
channels = 1,
|
||||
rate = 24000,
|
||||
sampleWidth = 2,
|
||||
) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const writer = new wav.FileWriter(filename, {
|
||||
channels,
|
||||
sampleRate: rate,
|
||||
bitDepth: sampleWidth * 8,
|
||||
});
|
||||
|
||||
writer.on('finish', resolve);
|
||||
writer.on('error', reject);
|
||||
|
||||
writer.write(pcmData);
|
||||
writer.end();
|
||||
});
|
||||
}
|
||||
|
||||
async function main() {
|
||||
const response = await ai.models.generateContent({
|
||||
model: "gemini-2.5-flash-lite",
|
||||
contents: "Что ты умеешь делать? На какой модели ты построен?",
|
||||
});
|
||||
console.log(response.text);
|
||||
}
|
||||
|
||||
|
||||
async function pepe(){
|
||||
const prompt = 'Нужно сделать анализ аудиофайла и вывести текстовую расшифровку.'
|
||||
|
||||
|
||||
const response = await ai.models.generateContent({
|
||||
model: "gemini-3-flash-preview",
|
||||
contents: {
|
||||
parts:[
|
||||
{
|
||||
fileData: {
|
||||
fileUri:AUDIO_URL,
|
||||
},
|
||||
},
|
||||
{
|
||||
text: prompt
|
||||
}
|
||||
]
|
||||
}
|
||||
})
|
||||
console.log(response.text)
|
||||
}
|
||||
|
||||
async function shneine(){
|
||||
const myfile = await ai.files.upload({
|
||||
file:'./pedik.ogg',
|
||||
config:{
|
||||
mimeType:'audio/ogg',
|
||||
}
|
||||
});
|
||||
|
||||
const response = await ai.models.generateContent({
|
||||
model: "gemini-3-flash-preview",
|
||||
contents: createUserContent([
|
||||
createPartFromUri(myfile.uri, myfile.mimeType),
|
||||
'Нужно сделать анализ аудиофайла, краткую выжимку самого важного, вывести тезисы.'
|
||||
])
|
||||
})
|
||||
console.log(response.text)
|
||||
}
|
||||
//await shneine();
|
||||
|
||||
|
||||
async function fawatafa() {
|
||||
const response = await ai.models.generateContent({
|
||||
model: "gemini-2.5-flash-preview-tts",
|
||||
contents: [{ parts: [{ text: `Say aggresive: А перекинул я этот пост, потому что его Саша переслал. И вот вдумайся: Саше 30 лет, и вот на него это полностью работает. То есть он верит, что можно заставить Дурова открыть представительство в России, и это снимет к нему все вопросы, и Телеграм оставят незаблокированным` }] }],
|
||||
config: {
|
||||
responseModalities: ['AUDIO'],
|
||||
speechConfig: {
|
||||
voiceConfig: {
|
||||
prebuiltVoiceConfig: { voiceName: 'Leda' },
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const data = response.candidates?.[0]?.content?.parts?.[0]?.inlineData?.data;
|
||||
const audioBuffer = Buffer.from(data, 'base64');
|
||||
|
||||
const fileName = 'outMarat5.wav';
|
||||
await saveWaveFile(fileName, audioBuffer);
|
||||
}
|
||||
|
||||
await fawatafa();
|
||||
Reference in New Issue
Block a user