Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a67c5ea9af | ||
|
|
e0dd03411d | ||
|
|
74ae2863a7 | ||
|
|
f7c4793dc2 |
@@ -1,8 +1,8 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
package="br.carinha.rosto"
|
package="br.carinha.rosto"
|
||||||
android:versionCode="9"
|
android:versionCode="10"
|
||||||
android:versionName="0.8.1">
|
android:versionName="0.8.2">
|
||||||
|
|
||||||
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="34" />
|
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="34" />
|
||||||
|
|
||||||
|
|||||||
@@ -26,6 +26,7 @@
|
|||||||
</svg>
|
</svg>
|
||||||
<div id="fps"></div>
|
<div id="fps"></div>
|
||||||
<script src="rosto-motor.js"></script>
|
<script src="rosto-motor.js"></script>
|
||||||
|
<script src="voz-robo.js"></script>
|
||||||
<script>
|
<script>
|
||||||
/* Token do servidor (o app Android abre a página com ?t=...): vai em todo pedido ao
|
/* Token do servidor (o app Android abre a página com ?t=...): vai em todo pedido ao
|
||||||
próprio servidor, inclusive os de reacoes-render.js. Sem ?t= nada muda. */
|
próprio servidor, inclusive os de reacoes-render.js. Sem ?t= nada muda. */
|
||||||
@@ -969,15 +970,31 @@ const SONS = {
|
|||||||
dormir: (c, t, v) => { nota(c, 440, t, 0.25, "sine", v * 0.6); nota(c, 330, t + 0.22, 0.5, "sine", v * 0.5); },
|
dormir: (c, t, v) => { nota(c, 440, t, 0.25, "sine", v * 0.6); nota(c, 330, t + 0.22, 0.5, "sine", v * 0.5); },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* Balbucio de robô para a resposta da conversa (voz-robo.js). Enquanto ele "fala",
|
||||||
|
os sons dos gestos ficam quietos para não embolar. */
|
||||||
|
function falar(texto) {
|
||||||
|
if (!AUDIO.ligado || !window.VozRobo) return;
|
||||||
|
const c = contextoAudio();
|
||||||
|
if (!c) return;
|
||||||
|
if (c.state === "suspended") { try { c.resume(); } catch (e) { /* sem gesto */ } }
|
||||||
|
try {
|
||||||
|
const dur = window.VozRobo.balbuciar(c, texto, AUDIO.volume * 0.85);
|
||||||
|
AUDIO.mudoAte = performance.now() + dur * 1000;
|
||||||
|
} catch (e) { /* segue sem voz */ }
|
||||||
|
}
|
||||||
|
|
||||||
function tocarSom(gesto) {
|
function tocarSom(gesto) {
|
||||||
if (!AUDIO.ligado) return false;
|
if (!AUDIO.ligado) return false;
|
||||||
|
if (AUDIO.mudoAte && performance.now() < AUDIO.mudoAte) return false;
|
||||||
|
const voz = window.VozRobo && window.VozRobo.sons.indexOf(gesto) >= 0;
|
||||||
const f = SONS[gesto];
|
const f = SONS[gesto];
|
||||||
if (!f) return false;
|
if (!voz && !f) return false;
|
||||||
const c = contextoAudio();
|
const c = contextoAudio();
|
||||||
if (!c) return false;
|
if (!c) return false;
|
||||||
if (c.state === "suspended") { try { c.resume(); } catch (e) { /* sem gesto */ } }
|
if (c.state === "suspended") { try { c.resume(); } catch (e) { /* sem gesto */ } }
|
||||||
try {
|
try {
|
||||||
f(c, c.currentTime + 0.02, AUDIO.volume);
|
if (voz) window.VozRobo.tocar(c, gesto, AUDIO.volume); // voz de robô sintetizada
|
||||||
|
else f(c, c.currentTime + 0.02, AUDIO.volume); // bipes antigos (reserva)
|
||||||
// aparece no logcat como CarinhaJS: ajuda a diagnosticar audio mudo
|
// aparece no logcat como CarinhaJS: ajuda a diagnosticar audio mudo
|
||||||
console.log("voz: " + gesto + " ctx=" + c.state);
|
console.log("voz: " + gesto + " ctx=" + c.state);
|
||||||
return true;
|
return true;
|
||||||
@@ -1064,6 +1081,7 @@ setTimeout(relatar, 1500);
|
|||||||
try{const response=await fetch('/conversa/status',{cache:'no-store',signal:AbortSignal.timeout(2500)});if(!response.ok)return;
|
try{const response=await fetch('/conversa/status',{cache:'no-store',signal:AbortSignal.timeout(2500)});if(!response.ok)return;
|
||||||
const s=await response.json(),m=s.ultima;if(!m){seen=null;return;}
|
const s=await response.json(),m=s.ultima;if(!m){seen=null;return;}
|
||||||
if(m.id===seen||Date.now()/1000-m.horario>60)return;seen=m.id;
|
if(m.id===seen||Date.now()/1000-m.horario>60)return;seen=m.id;
|
||||||
|
falar(m.texto);
|
||||||
MIC.ultimoSom=performance.now()/1000;trata('acordar');trata(m.gesto);
|
MIC.ultimoSom=performance.now()/1000;trata('acordar');trata(m.gesto);
|
||||||
if(window.MotorRosto)window.MotorRosto.faixa('legenda',{texto:m.texto});
|
if(window.MotorRosto)window.MotorRosto.faixa('legenda',{texto:m.texto});
|
||||||
}catch(e){}finally{fetching=false;}
|
}catch(e){}finally{fetching=false;}
|
||||||
@@ -1113,6 +1131,7 @@ if(new URLSearchParams(location.search).get('aparelho')==='1' && new URLSearchPa
|
|||||||
const m = s.ultima;
|
const m = s.ultima;
|
||||||
if (!m || m.id === ultimaConversa || Date.now() / 1000 - m.horario > 60) return;
|
if (!m || m.id === ultimaConversa || Date.now() / 1000 - m.horario > 60) return;
|
||||||
ultimaConversa = m.id;
|
ultimaConversa = m.id;
|
||||||
|
falar(m.texto);
|
||||||
MIC.ultimoSom = performance.now() / 1000; trata('acordar'); trata(m.gesto);
|
MIC.ultimoSom = performance.now() / 1000; trata('acordar'); trata(m.gesto);
|
||||||
if (window.MotorRosto) window.MotorRosto.faixa('legenda', { texto: m.texto });
|
if (window.MotorRosto) window.MotorRosto.faixa('legenda', { texto: m.texto });
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -12,8 +12,13 @@ let config = {}, signature = '', movementEnabled = true, aviso = '', capacidades
|
|||||||
let allowed = true;
|
let allowed = true;
|
||||||
let lastMotionFrame = -1;
|
let lastMotionFrame = -1;
|
||||||
function chave(c) { return JSON.stringify([c.cameraLado || 'user', c.videoResolucao || 'auto', c.videoFPS || 0]); }
|
function chave(c) { return JSON.stringify([c.cameraLado || 'user', c.videoResolucao || 'auto', c.videoFPS || 0]); }
|
||||||
|
/* Nada pode esperar para sempre: se a câmera estiver presa (ex.: servidor caiu no meio e o
|
||||||
|
sensor de movimento ainda a segura), desiste e a próxima mensagem do painel tenta de novo. */
|
||||||
|
function comPrazo(promessa, ms, oque) {
|
||||||
|
return Promise.race([promessa, new Promise((_, rej) => setTimeout(() => rej(new Error(oque + ' demorou mais de ' + ms / 1000 + ' s')), ms))]);
|
||||||
|
}
|
||||||
async function capturar(c) {
|
async function capturar(c) {
|
||||||
const media = await navigator.mediaDevices.getUserMedia({audio:false,video:{facingMode:{ideal:c.cameraLado || 'user'},width:{ideal:640},height:{ideal:360},frameRate:{ideal:30}}});
|
const media = await comPrazo(navigator.mediaDevices.getUserMedia({audio:false,video:{facingMode:{ideal:c.cameraLado || 'user'},width:{ideal:640},height:{ideal:360},frameRate:{ideal:30}}}), 8000, 'Abrir a câmera');
|
||||||
const track = media.getVideoTracks()[0];
|
const track = media.getVideoTracks()[0];
|
||||||
const facing = track.getSettings().facingMode;
|
const facing = track.getSettings().facingMode;
|
||||||
if (facing && facing !== (c.cameraLado || 'user')) {
|
if (facing && facing !== (c.cameraLado || 'user')) {
|
||||||
@@ -74,6 +79,12 @@ async function iniciar(id) {
|
|||||||
const media = await capturar(config); signature = chave(config);
|
const media = await capturar(config); signature = chave(config);
|
||||||
if (!wanted || captureGeneration !== generation) { media.getTracks().forEach(t => t.stop()); return; }
|
if (!wanted || captureGeneration !== generation) { media.getTracks().forEach(t => t.stop()); return; }
|
||||||
stream = media; video.srcObject = stream; await video.play();
|
stream = media; video.srcObject = stream; await video.play();
|
||||||
|
// câmera fechada de repente (outro uso, erro do sistema): desfaz tudo; o próximo pacote reabre
|
||||||
|
stream.getVideoTracks()[0].onended = () => {
|
||||||
|
if (captureGeneration !== generation) return;
|
||||||
|
console.log('RTC câmera encerrada; recomeçando no próximo pedido');
|
||||||
|
parar(); sid = null;
|
||||||
|
};
|
||||||
pc = new RTCPeerConnection({iceServers:[]});
|
pc = new RTCPeerConnection({iceServers:[]});
|
||||||
sender = pc.addTrack(stream.getVideoTracks()[0], stream);
|
sender = pc.addTrack(stream.getVideoTracks()[0], stream);
|
||||||
const mine = pc;
|
const mine = pc;
|
||||||
@@ -133,11 +144,11 @@ async function receber(packet) {
|
|||||||
}
|
}
|
||||||
window.rtcReceber = packet => {
|
window.rtcReceber = packet => {
|
||||||
allowed = true;
|
allowed = true;
|
||||||
tasks = tasks.then(() => allowed ? receber(packet) : undefined).catch(e => {
|
tasks = tasks.then(() => allowed ? comPrazo(receber(packet), 12000, 'Pedido de vídeo') : undefined).catch(e => {
|
||||||
console.log('RTC erro=' + e.name + ': ' + e.message);
|
console.log('RTC erro=' + e.name + ': ' + e.message);
|
||||||
sinal({tipo:'erro',erro:e.name + ': ' + e.message});
|
sinal({tipo:'erro',erro:e.name + ': ' + e.message});
|
||||||
estado({tipo:'webrtc',estado:'erro',erro:e.message});
|
estado({tipo:'webrtc',estado:'erro',erro:e.message});
|
||||||
parar();
|
parar(); sid = null;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
window.rtcParar = () => { allowed = false; parar(); sid = null; };
|
window.rtcParar = () => { allowed = false; parar(); sid = null; };
|
||||||
|
|||||||
@@ -0,0 +1,188 @@
|
|||||||
|
/* voz-robo.js — voz sintetizada do Carinha, no estilo dos robozinhos de cinema.
|
||||||
|
*
|
||||||
|
* Tudo é gerado na hora com Web Audio: nenhuma gravação, nenhum arquivo de terceiros.
|
||||||
|
* Cada som é uma sequência de "sílabas": um oscilador que desliza de um tom a outro, com vibrato,
|
||||||
|
* passando por um filtro de formante (a "vogal": o→i faz o "uou"). Motores das mãos viram ruído
|
||||||
|
* filtrado, e a resposta da conversa vira um balbucio que sobe no fim quando é pergunta.
|
||||||
|
*/
|
||||||
|
(function () {
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
let ruido = null; // buffer de ruído reaproveitado
|
||||||
|
const TOM = 1.25; // todas as sílabas 25% acima do tom escrito
|
||||||
|
const saidas = new WeakMap(); // AudioContext → nó de saída (compressor)
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Cadeia de "brilho metálico" (criada uma vez por AudioContext):
|
||||||
|
* voz → ressonância de lata fina (agudo, ~850 Hz) → saturação leve → compressor → saída
|
||||||
|
* Nada grave: zumbido e ressonância graves deixavam a voz com cara de sapo.
|
||||||
|
*/
|
||||||
|
function saida(c) {
|
||||||
|
if (saidas.has(c)) return saidas.get(c);
|
||||||
|
const entrada = c.createGain();
|
||||||
|
const seca = c.createGain(); seca.gain.value = 0.8;
|
||||||
|
const atraso = c.createDelay(0.05); atraso.delayTime.value = 0.00118;
|
||||||
|
const volta = c.createGain(); volta.gain.value = 0.42;
|
||||||
|
const molhada = c.createGain(); molhada.gain.value = 0.35;
|
||||||
|
entrada.connect(seca);
|
||||||
|
entrada.connect(atraso); atraso.connect(volta); volta.connect(atraso); atraso.connect(molhada);
|
||||||
|
const satura = c.createWaveShaper();
|
||||||
|
const n = 2048, curva = new Float32Array(n);
|
||||||
|
for (let i = 0; i < n; i++) { const x = (i / (n - 1)) * 2 - 1; curva[i] = Math.tanh(x * 1.3); }
|
||||||
|
satura.curve = curva;
|
||||||
|
seca.connect(satura); molhada.connect(satura);
|
||||||
|
const brilho = c.createBiquadFilter(); // realce leve nos agudos: "metal" limpo
|
||||||
|
brilho.type = 'peaking'; brilho.frequency.value = 3200; brilho.Q.value = 1.2; brilho.gain.value = 4;
|
||||||
|
const comp = c.createDynamicsCompressor();
|
||||||
|
comp.threshold.value = -16; comp.ratio.value = 4; comp.attack.value = 0.003; comp.release.value = 0.15;
|
||||||
|
const passaBaixa = c.createBiquadFilter();
|
||||||
|
passaBaixa.type = 'lowpass'; passaBaixa.frequency.value = 8000;
|
||||||
|
const volume = c.createGain(); volume.gain.value = 0.8;
|
||||||
|
satura.connect(brilho); brilho.connect(comp); comp.connect(passaBaixa); passaBaixa.connect(volume); volume.connect(c.destination);
|
||||||
|
saidas.set(c, entrada);
|
||||||
|
return entrada;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Uma sílaba. de/para: tom em Hz; vogal: [formante inicial, final] em Hz;
|
||||||
|
* vib: [Hz, profundidade em Hz]; forma: tipo de onda.
|
||||||
|
*/
|
||||||
|
function silaba(c, t0, dur, de, para, vol, op) {
|
||||||
|
op = op || {};
|
||||||
|
vol *= 2.4; // compensa a energia que o filtro de formante tira
|
||||||
|
de *= TOM; para *= TOM; // voz de robozinho: aguda
|
||||||
|
const osc = c.createOscillator();
|
||||||
|
osc.type = op.forma || 'sawtooth';
|
||||||
|
osc.frequency.setValueAtTime(de, t0);
|
||||||
|
osc.frequency.exponentialRampToValueAtTime(Math.max(20, para), t0 + dur);
|
||||||
|
if (op.vib) {
|
||||||
|
const lfo = c.createOscillator(), prof = c.createGain();
|
||||||
|
lfo.frequency.value = op.vib[0]; prof.gain.value = op.vib[1];
|
||||||
|
lfo.connect(prof); prof.connect(osc.frequency);
|
||||||
|
lfo.start(t0); lfo.stop(t0 + dur + 0.05);
|
||||||
|
}
|
||||||
|
// FM harmônico e leve: brilho de metal sem aspereza
|
||||||
|
const mod = c.createOscillator(), modProf = c.createGain();
|
||||||
|
mod.type = 'sine';
|
||||||
|
mod.frequency.setValueAtTime(de * 2, t0);
|
||||||
|
mod.frequency.exponentialRampToValueAtTime(Math.max(20, para * 2), t0 + dur);
|
||||||
|
modProf.gain.setValueAtTime(de * (op.metal ?? 0.22), t0);
|
||||||
|
modProf.gain.exponentialRampToValueAtTime(Math.max(1, para * (op.metal ?? 0.22)), t0 + dur);
|
||||||
|
mod.connect(modProf); modProf.connect(osc.frequency);
|
||||||
|
mod.start(t0); mod.stop(t0 + dur + 0.05);
|
||||||
|
// corpo: uma senoide uma oitava abaixo deixa a voz menos "apito"
|
||||||
|
const sub = c.createOscillator();
|
||||||
|
sub.type = 'sine';
|
||||||
|
sub.frequency.setValueAtTime(de / 2, t0);
|
||||||
|
sub.frequency.exponentialRampToValueAtTime(Math.max(20, para / 2), t0 + dur);
|
||||||
|
const vogal = op.vogal || [900, 1500];
|
||||||
|
const filtro = c.createBiquadFilter();
|
||||||
|
filtro.type = 'bandpass'; filtro.Q.value = op.q || 5;
|
||||||
|
filtro.frequency.setValueAtTime(vogal[0], t0);
|
||||||
|
filtro.frequency.exponentialRampToValueAtTime(vogal[1], t0 + dur);
|
||||||
|
const g = c.createGain(), gs = c.createGain();
|
||||||
|
const ataque = Math.min(0.02, dur * 0.25);
|
||||||
|
g.gain.setValueAtTime(0.0001, t0);
|
||||||
|
g.gain.exponentialRampToValueAtTime(vol, t0 + ataque);
|
||||||
|
g.gain.setValueAtTime(vol, t0 + dur * 0.7);
|
||||||
|
g.gain.exponentialRampToValueAtTime(0.0001, t0 + dur);
|
||||||
|
gs.gain.value = 0.12; // pouca oitava de baixo: grave demais vira coaxar
|
||||||
|
osc.connect(filtro); sub.connect(gs); gs.connect(filtro); filtro.connect(g); g.connect(saida(c));
|
||||||
|
osc.start(t0); sub.start(t0);
|
||||||
|
osc.stop(t0 + dur + 0.05); sub.stop(t0 + dur + 0.05);
|
||||||
|
}
|
||||||
|
|
||||||
|
function bufferRuido(c) {
|
||||||
|
if (ruido && ruido.sampleRate === c.sampleRate) return ruido;
|
||||||
|
ruido = c.createBuffer(1, c.sampleRate, c.sampleRate);
|
||||||
|
const d = ruido.getChannelData(0);
|
||||||
|
for (let i = 0; i < d.length; i++) d[i] = Math.random() * 2 - 1;
|
||||||
|
return ruido;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Motorzinho: ruído filtrado que sobe de tom, com um tremor mecânico. */
|
||||||
|
function servo(c, t0, dur, vol, sobe) {
|
||||||
|
const fonte = c.createBufferSource();
|
||||||
|
fonte.buffer = bufferRuido(c); fonte.loop = true;
|
||||||
|
const f = c.createBiquadFilter();
|
||||||
|
f.type = 'bandpass'; f.Q.value = 9;
|
||||||
|
f.frequency.setValueAtTime(sobe === false ? 1500 : 500, t0);
|
||||||
|
f.frequency.exponentialRampToValueAtTime(sobe === false ? 500 : 1500, t0 + dur);
|
||||||
|
const g = c.createGain(), trem = c.createOscillator(), tg = c.createGain();
|
||||||
|
trem.frequency.value = 38; tg.gain.value = vol * 0.35;
|
||||||
|
trem.connect(tg); tg.connect(g.gain);
|
||||||
|
g.gain.setValueAtTime(0.0001, t0);
|
||||||
|
g.gain.exponentialRampToValueAtTime(vol * 0.6, t0 + 0.05);
|
||||||
|
g.gain.setValueAtTime(vol * 0.6, t0 + dur - 0.06);
|
||||||
|
g.gain.exponentialRampToValueAtTime(0.0001, t0 + dur);
|
||||||
|
fonte.connect(f); f.connect(g); g.connect(saida(c));
|
||||||
|
fonte.start(t0); trem.start(t0);
|
||||||
|
fonte.stop(t0 + dur + 0.05); trem.stop(t0 + dur + 0.05);
|
||||||
|
}
|
||||||
|
|
||||||
|
function clique(c, t0, vol) {
|
||||||
|
const fonte = c.createBufferSource();
|
||||||
|
fonte.buffer = bufferRuido(c);
|
||||||
|
const f = c.createBiquadFilter(); f.type = 'highpass'; f.frequency.value = 3000;
|
||||||
|
const g = c.createGain();
|
||||||
|
g.gain.setValueAtTime(vol * 0.5, t0); g.gain.exponentialRampToValueAtTime(0.0001, t0 + 0.03);
|
||||||
|
fonte.connect(f); f.connect(g); g.connect(saida(c));
|
||||||
|
fonte.start(t0); fonte.stop(t0 + 0.05);
|
||||||
|
}
|
||||||
|
|
||||||
|
const O = [500, 900], I = [1800, 2400], U = [350, 700], A = [900, 1300]; // vogais (formantes)
|
||||||
|
|
||||||
|
// Cada som: (c, t, v) → agenda as sílabas. Volumes relativos ao volume do app.
|
||||||
|
const SONS = {
|
||||||
|
feliz: (c, t, v) => { silaba(c, t, 0.12, 620, 900, v, { vogal: [1200, 2000] }); silaba(c, t + 0.13, 0.18, 900, 1250, v, { vogal: I, vib: [9, 18] }); },
|
||||||
|
alegre: (c, t, v) => [560, 700, 860, 1100].forEach((f, i) => silaba(c, t + i * 0.085, 0.09, f, f * 1.25, v * 0.85, { vogal: I, forma: 'square' })),
|
||||||
|
coracao: (c, t, v) => { silaba(c, t, 0.55, 760, 560, v, { vogal: [800, 1300], vib: [7, 28] }); },
|
||||||
|
piscadinha: (c, t, v) => { clique(c, t, v); silaba(c, t + 0.04, 0.08, 1000, 1300, v * 0.6, { forma: 'square', vogal: I }); },
|
||||||
|
surpreso: (c, t, v) => { silaba(c, t, 0.22, 260, 1100, v, { vogal: [450, 2000] }); silaba(c, t + 0.22, 0.12, 1100, 820, v * 0.8, { vogal: I }); },
|
||||||
|
bravo: (c, t, v) => [0, 0.13, 0.26].forEach((d, i) => silaba(c, t + d, 0.1, 480 - i * 30, 380 - i * 30, v * 0.85, { forma: 'square', vogal: [1300, 900] })), // bipes zangados
|
||||||
|
triste: (c, t, v) => { silaba(c, t, 0.65, 640, 380, v * 0.85, { vogal: [1200, 750], vib: [5, 14] }); },
|
||||||
|
dormir: (c, t, v) => { silaba(c, t, 0.35, 460, 760, v * 0.7, { vogal: [900, 1500] }); silaba(c, t + 0.36, 0.75, 760, 340, v * 0.6, { vogal: [1500, 700], vib: [4, 8] }); },
|
||||||
|
acordar: (c, t, v) => { servo(c, t, 0.25, v * 0.5); [300, 450, 700].forEach((f, i) => silaba(c, t + 0.22 + i * 0.1, 0.1, f, f * 1.2, v * 0.8, { vogal: I, forma: 'square' })); silaba(c, t + 0.56, 0.2, 700, 1050, v, { vogal: [1200, 2200], vib: [8, 15] }); },
|
||||||
|
acenar: (c, t, v) => { servo(c, t, 0.3, v * 0.45); silaba(c, t + 0.28, 0.13, 520, 820, v, { vogal: [1000, 1900] }); silaba(c, t + 0.44, 0.2, 760, 1080, v, { vogal: I, vib: [9, 20] }); },
|
||||||
|
esconder: (c, t, v) => { servo(c, t, 0.45, v * 0.5); silaba(c, t + 0.1, 0.08, 950, 1350, v * 0.8, { vogal: I }); for (let i = 0; i < 5; i++) silaba(c, t + 0.6 + i * 0.09, 0.05, 1200 + (i % 2) * 180, 1300, v * 0.35, { forma: 'square', vogal: I }); servo(c, t + 2.05, 0.4, v * 0.45, false); },
|
||||||
|
espiar: (c, t, v) => { servo(c, t, 0.45, v * 0.5); silaba(c, t + 1.0, 0.3, 480, 760, v * 0.9, { vogal: [600, 1700] }); silaba(c, t + 2.0, 0.16, 800, 1150, v, { vogal: I }); },
|
||||||
|
pensar: (c, t, v) => { servo(c, t, 0.35, v * 0.4); silaba(c, t + 0.35, 0.5, 520, 640, v * 0.7, { vogal: [900, 1600], vib: [5, 10] }); [0.95, 1.12].forEach((d) => silaba(c, t + d, 0.05, 1500, 1600, v * 0.35, { forma: 'square', vogal: I })); }, // "hmm?" e bipinhos
|
||||||
|
musica: (c, t, v) => [523, 659, 784, 659, 880, 784, 659, 1047].forEach((f, i) => silaba(c, t + i * 0.26, 0.2, f, f * 1.02, v * 0.6, { forma: 'triangle', vogal: A, vib: [6, 5] })),
|
||||||
|
};
|
||||||
|
|
||||||
|
// Gerador previsível: a mesma frase sempre "soa" igual.
|
||||||
|
function semente(texto) {
|
||||||
|
let h = 2166136261;
|
||||||
|
for (let i = 0; i < texto.length; i++) h = Math.imul(h ^ texto.charCodeAt(i), 16777619);
|
||||||
|
return () => { h = Math.imul(h ^ (h >>> 15), 2246822507); h = Math.imul(h ^ (h >>> 13), 3266489909); return ((h ^= h >>> 16) >>> 0) / 4294967296; };
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Balbucio de robô para uma resposta: ~1 sílaba a cada 6 letras, no máximo 16. */
|
||||||
|
function balbuciar(c, texto, v) {
|
||||||
|
texto = String(texto || '').trim();
|
||||||
|
if (!texto) return 0;
|
||||||
|
const rnd = semente(texto), n = Math.max(2, Math.min(16, Math.ceil(texto.length / 6)));
|
||||||
|
const pergunta = /\?\s*$/.test(texto), exclama = /!\s*$/.test(texto);
|
||||||
|
const vogais = [O, I, A, U];
|
||||||
|
let t = c.currentTime + 0.03, tom = 520 + rnd() * 180;
|
||||||
|
for (let i = 0; i < n; i++) {
|
||||||
|
const ultima = i === n - 1;
|
||||||
|
const dur = 0.07 + rnd() * 0.1;
|
||||||
|
let para = tom * (0.8 + rnd() * 0.5);
|
||||||
|
if (ultima) para = pergunta ? tom * 1.6 : exclama ? tom * 1.35 : tom * 0.7;
|
||||||
|
silaba(c, t, ultima ? dur + 0.08 : dur, tom, para, v * (0.65 + rnd() * 0.3), { vogal: vogais[Math.floor(rnd() * 4)], vib: rnd() < 0.3 ? [8, 14] : null, forma: rnd() < 0.25 ? 'square' : 'sawtooth' });
|
||||||
|
t += dur + 0.025 + rnd() * 0.05;
|
||||||
|
tom = Math.max(330, Math.min(1000, para * (0.9 + rnd() * 0.25)));
|
||||||
|
}
|
||||||
|
return t - c.currentTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
function tocar(c, nome, v) {
|
||||||
|
const f = SONS[nome];
|
||||||
|
if (!f || !c) return false;
|
||||||
|
f(c, c.currentTime + 0.02, v);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
window.VozRobo = { tocar, balbuciar, servo: (c, dur, v) => servo(c, c.currentTime + 0.01, dur, v), sons: Object.keys(SONS) };
|
||||||
|
})();
|
||||||
@@ -30,7 +30,7 @@ def main():
|
|||||||
def run(*command):
|
def run(*command):
|
||||||
subprocess.run([str(x) for x in command], check=True)
|
subprocess.run([str(x) for x in command], check=True)
|
||||||
|
|
||||||
for name in ('carinha.html', 'camera.html', 'rosto-motor.js'):
|
for name in ('carinha.html', 'camera.html', 'rosto-motor.js', 'voz-robo.js'):
|
||||||
shutil.copy2(HERE.parent / name, HERE / 'app/assets' / name)
|
shutil.copy2(HERE.parent / name, HERE / 'app/assets' / name)
|
||||||
with tempfile.TemporaryDirectory(prefix='carinha-build-', dir=work) as folder:
|
with tempfile.TemporaryDirectory(prefix='carinha-build-', dir=work) as folder:
|
||||||
tmp = Path(folder)
|
tmp = Path(folder)
|
||||||
|
|||||||
+21
-2
@@ -26,6 +26,7 @@
|
|||||||
</svg>
|
</svg>
|
||||||
<div id="fps"></div>
|
<div id="fps"></div>
|
||||||
<script src="rosto-motor.js"></script>
|
<script src="rosto-motor.js"></script>
|
||||||
|
<script src="voz-robo.js"></script>
|
||||||
<script>
|
<script>
|
||||||
/* Token do servidor (o app Android abre a página com ?t=...): vai em todo pedido ao
|
/* Token do servidor (o app Android abre a página com ?t=...): vai em todo pedido ao
|
||||||
próprio servidor, inclusive os de reacoes-render.js. Sem ?t= nada muda. */
|
próprio servidor, inclusive os de reacoes-render.js. Sem ?t= nada muda. */
|
||||||
@@ -969,15 +970,31 @@ const SONS = {
|
|||||||
dormir: (c, t, v) => { nota(c, 440, t, 0.25, "sine", v * 0.6); nota(c, 330, t + 0.22, 0.5, "sine", v * 0.5); },
|
dormir: (c, t, v) => { nota(c, 440, t, 0.25, "sine", v * 0.6); nota(c, 330, t + 0.22, 0.5, "sine", v * 0.5); },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* Balbucio de robô para a resposta da conversa (voz-robo.js). Enquanto ele "fala",
|
||||||
|
os sons dos gestos ficam quietos para não embolar. */
|
||||||
|
function falar(texto) {
|
||||||
|
if (!AUDIO.ligado || !window.VozRobo) return;
|
||||||
|
const c = contextoAudio();
|
||||||
|
if (!c) return;
|
||||||
|
if (c.state === "suspended") { try { c.resume(); } catch (e) { /* sem gesto */ } }
|
||||||
|
try {
|
||||||
|
const dur = window.VozRobo.balbuciar(c, texto, AUDIO.volume * 0.85);
|
||||||
|
AUDIO.mudoAte = performance.now() + dur * 1000;
|
||||||
|
} catch (e) { /* segue sem voz */ }
|
||||||
|
}
|
||||||
|
|
||||||
function tocarSom(gesto) {
|
function tocarSom(gesto) {
|
||||||
if (!AUDIO.ligado) return false;
|
if (!AUDIO.ligado) return false;
|
||||||
|
if (AUDIO.mudoAte && performance.now() < AUDIO.mudoAte) return false;
|
||||||
|
const voz = window.VozRobo && window.VozRobo.sons.indexOf(gesto) >= 0;
|
||||||
const f = SONS[gesto];
|
const f = SONS[gesto];
|
||||||
if (!f) return false;
|
if (!voz && !f) return false;
|
||||||
const c = contextoAudio();
|
const c = contextoAudio();
|
||||||
if (!c) return false;
|
if (!c) return false;
|
||||||
if (c.state === "suspended") { try { c.resume(); } catch (e) { /* sem gesto */ } }
|
if (c.state === "suspended") { try { c.resume(); } catch (e) { /* sem gesto */ } }
|
||||||
try {
|
try {
|
||||||
f(c, c.currentTime + 0.02, AUDIO.volume);
|
if (voz) window.VozRobo.tocar(c, gesto, AUDIO.volume); // voz de robô sintetizada
|
||||||
|
else f(c, c.currentTime + 0.02, AUDIO.volume); // bipes antigos (reserva)
|
||||||
// aparece no logcat como CarinhaJS: ajuda a diagnosticar audio mudo
|
// aparece no logcat como CarinhaJS: ajuda a diagnosticar audio mudo
|
||||||
console.log("voz: " + gesto + " ctx=" + c.state);
|
console.log("voz: " + gesto + " ctx=" + c.state);
|
||||||
return true;
|
return true;
|
||||||
@@ -1064,6 +1081,7 @@ setTimeout(relatar, 1500);
|
|||||||
try{const response=await fetch('/conversa/status',{cache:'no-store',signal:AbortSignal.timeout(2500)});if(!response.ok)return;
|
try{const response=await fetch('/conversa/status',{cache:'no-store',signal:AbortSignal.timeout(2500)});if(!response.ok)return;
|
||||||
const s=await response.json(),m=s.ultima;if(!m){seen=null;return;}
|
const s=await response.json(),m=s.ultima;if(!m){seen=null;return;}
|
||||||
if(m.id===seen||Date.now()/1000-m.horario>60)return;seen=m.id;
|
if(m.id===seen||Date.now()/1000-m.horario>60)return;seen=m.id;
|
||||||
|
falar(m.texto);
|
||||||
MIC.ultimoSom=performance.now()/1000;trata('acordar');trata(m.gesto);
|
MIC.ultimoSom=performance.now()/1000;trata('acordar');trata(m.gesto);
|
||||||
if(window.MotorRosto)window.MotorRosto.faixa('legenda',{texto:m.texto});
|
if(window.MotorRosto)window.MotorRosto.faixa('legenda',{texto:m.texto});
|
||||||
}catch(e){}finally{fetching=false;}
|
}catch(e){}finally{fetching=false;}
|
||||||
@@ -1113,6 +1131,7 @@ if(new URLSearchParams(location.search).get('aparelho')==='1' && new URLSearchPa
|
|||||||
const m = s.ultima;
|
const m = s.ultima;
|
||||||
if (!m || m.id === ultimaConversa || Date.now() / 1000 - m.horario > 60) return;
|
if (!m || m.id === ultimaConversa || Date.now() / 1000 - m.horario > 60) return;
|
||||||
ultimaConversa = m.id;
|
ultimaConversa = m.id;
|
||||||
|
falar(m.texto);
|
||||||
MIC.ultimoSom = performance.now() / 1000; trata('acordar'); trata(m.gesto);
|
MIC.ultimoSom = performance.now() / 1000; trata('acordar'); trata(m.gesto);
|
||||||
if (window.MotorRosto) window.MotorRosto.faixa('legenda', { texto: m.texto });
|
if (window.MotorRosto) window.MotorRosto.faixa('legenda', { texto: m.texto });
|
||||||
});
|
});
|
||||||
|
|||||||
+1
-1
@@ -28,7 +28,7 @@ Set-Location $PSScriptRoot -ErrorAction Stop
|
|||||||
$arquivos = @(
|
$arquivos = @(
|
||||||
'kiosk-server.py', 'comum.py', 'eventos.py', 'controle_pc.py', 'sinalizacao.py', 'servos.py', 'braco.py',
|
'kiosk-server.py', 'comum.py', 'eventos.py', 'controle_pc.py', 'sinalizacao.py', 'servos.py', 'braco.py',
|
||||||
'cerebro.py', 'conversa.py', 'gemini.py', 'treinamento.py', 'figurinhas.py', 'api_config.py',
|
'cerebro.py', 'conversa.py', 'gemini.py', 'treinamento.py', 'figurinhas.py', 'api_config.py',
|
||||||
'carinha.html', 'camera.html', 'reacoes-render.js', 'rastreador-worker.js', 'rosto-motor.js', 'version.json',
|
'carinha.html', 'camera.html', 'reacoes-render.js', 'rastreador-worker.js', 'rosto-motor.js', 'voz-robo.js', 'version.json',
|
||||||
'obter-rastreamento.py', 'android/app/assets/qualidade-auto.js'
|
'obter-rastreamento.py', 'android/app/assets/qualidade-auto.js'
|
||||||
)
|
)
|
||||||
if (Test-Path 'android/carinha-rosto.apk') { $arquivos += 'android/carinha-rosto.apk' }
|
if (Test-Path 'android/carinha-rosto.apk') { $arquivos += 'android/carinha-rosto.apk' }
|
||||||
|
|||||||
+1
-1
@@ -62,7 +62,7 @@ APARENCIA = {"rosto": "carinha", "cor": [92, 214, 255], "formato": "padrao"}
|
|||||||
ARQUIVO_APARENCIA = "aparencia.json"
|
ARQUIVO_APARENCIA = "aparencia.json"
|
||||||
|
|
||||||
# Arquivos servidos como estão: o rosto do celular e o rastreamento do painel.
|
# Arquivos servidos como estão: o rosto do celular e o rastreamento do painel.
|
||||||
ESTATICOS = {"/carinha.html", "/camera.html", "/reacoes-render.js", "/rastreador-worker.js", "/rosto-motor.js",
|
ESTATICOS = {"/carinha.html", "/camera.html", "/reacoes-render.js", "/rastreador-worker.js", "/rosto-motor.js", "/voz-robo.js",
|
||||||
"/vendor/mediapipe/vision_bundle.mjs", "/vendor/mediapipe/face.tflite", "/vendor/mediapipe/hands.task",
|
"/vendor/mediapipe/vision_bundle.mjs", "/vendor/mediapipe/face.tflite", "/vendor/mediapipe/hands.task",
|
||||||
"/vendor/mediapipe/wasm/vision_wasm_internal.js", "/vendor/mediapipe/wasm/vision_wasm_internal.wasm",
|
"/vendor/mediapipe/wasm/vision_wasm_internal.js", "/vendor/mediapipe/wasm/vision_wasm_internal.wasm",
|
||||||
"/vendor/mediapipe/wasm/vision_wasm_nosimd_internal.js", "/vendor/mediapipe/wasm/vision_wasm_nosimd_internal.wasm"}
|
"/vendor/mediapipe/wasm/vision_wasm_nosimd_internal.js", "/vendor/mediapipe/wasm/vision_wasm_nosimd_internal.wasm"}
|
||||||
|
|||||||
+188
@@ -0,0 +1,188 @@
|
|||||||
|
/* voz-robo.js — voz sintetizada do Carinha, no estilo dos robozinhos de cinema.
|
||||||
|
*
|
||||||
|
* Tudo é gerado na hora com Web Audio: nenhuma gravação, nenhum arquivo de terceiros.
|
||||||
|
* Cada som é uma sequência de "sílabas": um oscilador que desliza de um tom a outro, com vibrato,
|
||||||
|
* passando por um filtro de formante (a "vogal": o→i faz o "uou"). Motores das mãos viram ruído
|
||||||
|
* filtrado, e a resposta da conversa vira um balbucio que sobe no fim quando é pergunta.
|
||||||
|
*/
|
||||||
|
(function () {
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
let ruido = null; // buffer de ruído reaproveitado
|
||||||
|
const TOM = 1.25; // todas as sílabas 25% acima do tom escrito
|
||||||
|
const saidas = new WeakMap(); // AudioContext → nó de saída (compressor)
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Cadeia de "brilho metálico" (criada uma vez por AudioContext):
|
||||||
|
* voz → ressonância de lata fina (agudo, ~850 Hz) → saturação leve → compressor → saída
|
||||||
|
* Nada grave: zumbido e ressonância graves deixavam a voz com cara de sapo.
|
||||||
|
*/
|
||||||
|
function saida(c) {
|
||||||
|
if (saidas.has(c)) return saidas.get(c);
|
||||||
|
const entrada = c.createGain();
|
||||||
|
const seca = c.createGain(); seca.gain.value = 0.8;
|
||||||
|
const atraso = c.createDelay(0.05); atraso.delayTime.value = 0.00118;
|
||||||
|
const volta = c.createGain(); volta.gain.value = 0.42;
|
||||||
|
const molhada = c.createGain(); molhada.gain.value = 0.35;
|
||||||
|
entrada.connect(seca);
|
||||||
|
entrada.connect(atraso); atraso.connect(volta); volta.connect(atraso); atraso.connect(molhada);
|
||||||
|
const satura = c.createWaveShaper();
|
||||||
|
const n = 2048, curva = new Float32Array(n);
|
||||||
|
for (let i = 0; i < n; i++) { const x = (i / (n - 1)) * 2 - 1; curva[i] = Math.tanh(x * 1.3); }
|
||||||
|
satura.curve = curva;
|
||||||
|
seca.connect(satura); molhada.connect(satura);
|
||||||
|
const brilho = c.createBiquadFilter(); // realce leve nos agudos: "metal" limpo
|
||||||
|
brilho.type = 'peaking'; brilho.frequency.value = 3200; brilho.Q.value = 1.2; brilho.gain.value = 4;
|
||||||
|
const comp = c.createDynamicsCompressor();
|
||||||
|
comp.threshold.value = -16; comp.ratio.value = 4; comp.attack.value = 0.003; comp.release.value = 0.15;
|
||||||
|
const passaBaixa = c.createBiquadFilter();
|
||||||
|
passaBaixa.type = 'lowpass'; passaBaixa.frequency.value = 8000;
|
||||||
|
const volume = c.createGain(); volume.gain.value = 0.8;
|
||||||
|
satura.connect(brilho); brilho.connect(comp); comp.connect(passaBaixa); passaBaixa.connect(volume); volume.connect(c.destination);
|
||||||
|
saidas.set(c, entrada);
|
||||||
|
return entrada;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Uma sílaba. de/para: tom em Hz; vogal: [formante inicial, final] em Hz;
|
||||||
|
* vib: [Hz, profundidade em Hz]; forma: tipo de onda.
|
||||||
|
*/
|
||||||
|
function silaba(c, t0, dur, de, para, vol, op) {
|
||||||
|
op = op || {};
|
||||||
|
vol *= 2.4; // compensa a energia que o filtro de formante tira
|
||||||
|
de *= TOM; para *= TOM; // voz de robozinho: aguda
|
||||||
|
const osc = c.createOscillator();
|
||||||
|
osc.type = op.forma || 'sawtooth';
|
||||||
|
osc.frequency.setValueAtTime(de, t0);
|
||||||
|
osc.frequency.exponentialRampToValueAtTime(Math.max(20, para), t0 + dur);
|
||||||
|
if (op.vib) {
|
||||||
|
const lfo = c.createOscillator(), prof = c.createGain();
|
||||||
|
lfo.frequency.value = op.vib[0]; prof.gain.value = op.vib[1];
|
||||||
|
lfo.connect(prof); prof.connect(osc.frequency);
|
||||||
|
lfo.start(t0); lfo.stop(t0 + dur + 0.05);
|
||||||
|
}
|
||||||
|
// FM harmônico e leve: brilho de metal sem aspereza
|
||||||
|
const mod = c.createOscillator(), modProf = c.createGain();
|
||||||
|
mod.type = 'sine';
|
||||||
|
mod.frequency.setValueAtTime(de * 2, t0);
|
||||||
|
mod.frequency.exponentialRampToValueAtTime(Math.max(20, para * 2), t0 + dur);
|
||||||
|
modProf.gain.setValueAtTime(de * (op.metal ?? 0.22), t0);
|
||||||
|
modProf.gain.exponentialRampToValueAtTime(Math.max(1, para * (op.metal ?? 0.22)), t0 + dur);
|
||||||
|
mod.connect(modProf); modProf.connect(osc.frequency);
|
||||||
|
mod.start(t0); mod.stop(t0 + dur + 0.05);
|
||||||
|
// corpo: uma senoide uma oitava abaixo deixa a voz menos "apito"
|
||||||
|
const sub = c.createOscillator();
|
||||||
|
sub.type = 'sine';
|
||||||
|
sub.frequency.setValueAtTime(de / 2, t0);
|
||||||
|
sub.frequency.exponentialRampToValueAtTime(Math.max(20, para / 2), t0 + dur);
|
||||||
|
const vogal = op.vogal || [900, 1500];
|
||||||
|
const filtro = c.createBiquadFilter();
|
||||||
|
filtro.type = 'bandpass'; filtro.Q.value = op.q || 5;
|
||||||
|
filtro.frequency.setValueAtTime(vogal[0], t0);
|
||||||
|
filtro.frequency.exponentialRampToValueAtTime(vogal[1], t0 + dur);
|
||||||
|
const g = c.createGain(), gs = c.createGain();
|
||||||
|
const ataque = Math.min(0.02, dur * 0.25);
|
||||||
|
g.gain.setValueAtTime(0.0001, t0);
|
||||||
|
g.gain.exponentialRampToValueAtTime(vol, t0 + ataque);
|
||||||
|
g.gain.setValueAtTime(vol, t0 + dur * 0.7);
|
||||||
|
g.gain.exponentialRampToValueAtTime(0.0001, t0 + dur);
|
||||||
|
gs.gain.value = 0.12; // pouca oitava de baixo: grave demais vira coaxar
|
||||||
|
osc.connect(filtro); sub.connect(gs); gs.connect(filtro); filtro.connect(g); g.connect(saida(c));
|
||||||
|
osc.start(t0); sub.start(t0);
|
||||||
|
osc.stop(t0 + dur + 0.05); sub.stop(t0 + dur + 0.05);
|
||||||
|
}
|
||||||
|
|
||||||
|
function bufferRuido(c) {
|
||||||
|
if (ruido && ruido.sampleRate === c.sampleRate) return ruido;
|
||||||
|
ruido = c.createBuffer(1, c.sampleRate, c.sampleRate);
|
||||||
|
const d = ruido.getChannelData(0);
|
||||||
|
for (let i = 0; i < d.length; i++) d[i] = Math.random() * 2 - 1;
|
||||||
|
return ruido;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Motorzinho: ruído filtrado que sobe de tom, com um tremor mecânico. */
|
||||||
|
function servo(c, t0, dur, vol, sobe) {
|
||||||
|
const fonte = c.createBufferSource();
|
||||||
|
fonte.buffer = bufferRuido(c); fonte.loop = true;
|
||||||
|
const f = c.createBiquadFilter();
|
||||||
|
f.type = 'bandpass'; f.Q.value = 9;
|
||||||
|
f.frequency.setValueAtTime(sobe === false ? 1500 : 500, t0);
|
||||||
|
f.frequency.exponentialRampToValueAtTime(sobe === false ? 500 : 1500, t0 + dur);
|
||||||
|
const g = c.createGain(), trem = c.createOscillator(), tg = c.createGain();
|
||||||
|
trem.frequency.value = 38; tg.gain.value = vol * 0.35;
|
||||||
|
trem.connect(tg); tg.connect(g.gain);
|
||||||
|
g.gain.setValueAtTime(0.0001, t0);
|
||||||
|
g.gain.exponentialRampToValueAtTime(vol * 0.6, t0 + 0.05);
|
||||||
|
g.gain.setValueAtTime(vol * 0.6, t0 + dur - 0.06);
|
||||||
|
g.gain.exponentialRampToValueAtTime(0.0001, t0 + dur);
|
||||||
|
fonte.connect(f); f.connect(g); g.connect(saida(c));
|
||||||
|
fonte.start(t0); trem.start(t0);
|
||||||
|
fonte.stop(t0 + dur + 0.05); trem.stop(t0 + dur + 0.05);
|
||||||
|
}
|
||||||
|
|
||||||
|
function clique(c, t0, vol) {
|
||||||
|
const fonte = c.createBufferSource();
|
||||||
|
fonte.buffer = bufferRuido(c);
|
||||||
|
const f = c.createBiquadFilter(); f.type = 'highpass'; f.frequency.value = 3000;
|
||||||
|
const g = c.createGain();
|
||||||
|
g.gain.setValueAtTime(vol * 0.5, t0); g.gain.exponentialRampToValueAtTime(0.0001, t0 + 0.03);
|
||||||
|
fonte.connect(f); f.connect(g); g.connect(saida(c));
|
||||||
|
fonte.start(t0); fonte.stop(t0 + 0.05);
|
||||||
|
}
|
||||||
|
|
||||||
|
const O = [500, 900], I = [1800, 2400], U = [350, 700], A = [900, 1300]; // vogais (formantes)
|
||||||
|
|
||||||
|
// Cada som: (c, t, v) → agenda as sílabas. Volumes relativos ao volume do app.
|
||||||
|
const SONS = {
|
||||||
|
feliz: (c, t, v) => { silaba(c, t, 0.12, 620, 900, v, { vogal: [1200, 2000] }); silaba(c, t + 0.13, 0.18, 900, 1250, v, { vogal: I, vib: [9, 18] }); },
|
||||||
|
alegre: (c, t, v) => [560, 700, 860, 1100].forEach((f, i) => silaba(c, t + i * 0.085, 0.09, f, f * 1.25, v * 0.85, { vogal: I, forma: 'square' })),
|
||||||
|
coracao: (c, t, v) => { silaba(c, t, 0.55, 760, 560, v, { vogal: [800, 1300], vib: [7, 28] }); },
|
||||||
|
piscadinha: (c, t, v) => { clique(c, t, v); silaba(c, t + 0.04, 0.08, 1000, 1300, v * 0.6, { forma: 'square', vogal: I }); },
|
||||||
|
surpreso: (c, t, v) => { silaba(c, t, 0.22, 260, 1100, v, { vogal: [450, 2000] }); silaba(c, t + 0.22, 0.12, 1100, 820, v * 0.8, { vogal: I }); },
|
||||||
|
bravo: (c, t, v) => [0, 0.13, 0.26].forEach((d, i) => silaba(c, t + d, 0.1, 480 - i * 30, 380 - i * 30, v * 0.85, { forma: 'square', vogal: [1300, 900] })), // bipes zangados
|
||||||
|
triste: (c, t, v) => { silaba(c, t, 0.65, 640, 380, v * 0.85, { vogal: [1200, 750], vib: [5, 14] }); },
|
||||||
|
dormir: (c, t, v) => { silaba(c, t, 0.35, 460, 760, v * 0.7, { vogal: [900, 1500] }); silaba(c, t + 0.36, 0.75, 760, 340, v * 0.6, { vogal: [1500, 700], vib: [4, 8] }); },
|
||||||
|
acordar: (c, t, v) => { servo(c, t, 0.25, v * 0.5); [300, 450, 700].forEach((f, i) => silaba(c, t + 0.22 + i * 0.1, 0.1, f, f * 1.2, v * 0.8, { vogal: I, forma: 'square' })); silaba(c, t + 0.56, 0.2, 700, 1050, v, { vogal: [1200, 2200], vib: [8, 15] }); },
|
||||||
|
acenar: (c, t, v) => { servo(c, t, 0.3, v * 0.45); silaba(c, t + 0.28, 0.13, 520, 820, v, { vogal: [1000, 1900] }); silaba(c, t + 0.44, 0.2, 760, 1080, v, { vogal: I, vib: [9, 20] }); },
|
||||||
|
esconder: (c, t, v) => { servo(c, t, 0.45, v * 0.5); silaba(c, t + 0.1, 0.08, 950, 1350, v * 0.8, { vogal: I }); for (let i = 0; i < 5; i++) silaba(c, t + 0.6 + i * 0.09, 0.05, 1200 + (i % 2) * 180, 1300, v * 0.35, { forma: 'square', vogal: I }); servo(c, t + 2.05, 0.4, v * 0.45, false); },
|
||||||
|
espiar: (c, t, v) => { servo(c, t, 0.45, v * 0.5); silaba(c, t + 1.0, 0.3, 480, 760, v * 0.9, { vogal: [600, 1700] }); silaba(c, t + 2.0, 0.16, 800, 1150, v, { vogal: I }); },
|
||||||
|
pensar: (c, t, v) => { servo(c, t, 0.35, v * 0.4); silaba(c, t + 0.35, 0.5, 520, 640, v * 0.7, { vogal: [900, 1600], vib: [5, 10] }); [0.95, 1.12].forEach((d) => silaba(c, t + d, 0.05, 1500, 1600, v * 0.35, { forma: 'square', vogal: I })); }, // "hmm?" e bipinhos
|
||||||
|
musica: (c, t, v) => [523, 659, 784, 659, 880, 784, 659, 1047].forEach((f, i) => silaba(c, t + i * 0.26, 0.2, f, f * 1.02, v * 0.6, { forma: 'triangle', vogal: A, vib: [6, 5] })),
|
||||||
|
};
|
||||||
|
|
||||||
|
// Gerador previsível: a mesma frase sempre "soa" igual.
|
||||||
|
function semente(texto) {
|
||||||
|
let h = 2166136261;
|
||||||
|
for (let i = 0; i < texto.length; i++) h = Math.imul(h ^ texto.charCodeAt(i), 16777619);
|
||||||
|
return () => { h = Math.imul(h ^ (h >>> 15), 2246822507); h = Math.imul(h ^ (h >>> 13), 3266489909); return ((h ^= h >>> 16) >>> 0) / 4294967296; };
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Balbucio de robô para uma resposta: ~1 sílaba a cada 6 letras, no máximo 16. */
|
||||||
|
function balbuciar(c, texto, v) {
|
||||||
|
texto = String(texto || '').trim();
|
||||||
|
if (!texto) return 0;
|
||||||
|
const rnd = semente(texto), n = Math.max(2, Math.min(16, Math.ceil(texto.length / 6)));
|
||||||
|
const pergunta = /\?\s*$/.test(texto), exclama = /!\s*$/.test(texto);
|
||||||
|
const vogais = [O, I, A, U];
|
||||||
|
let t = c.currentTime + 0.03, tom = 520 + rnd() * 180;
|
||||||
|
for (let i = 0; i < n; i++) {
|
||||||
|
const ultima = i === n - 1;
|
||||||
|
const dur = 0.07 + rnd() * 0.1;
|
||||||
|
let para = tom * (0.8 + rnd() * 0.5);
|
||||||
|
if (ultima) para = pergunta ? tom * 1.6 : exclama ? tom * 1.35 : tom * 0.7;
|
||||||
|
silaba(c, t, ultima ? dur + 0.08 : dur, tom, para, v * (0.65 + rnd() * 0.3), { vogal: vogais[Math.floor(rnd() * 4)], vib: rnd() < 0.3 ? [8, 14] : null, forma: rnd() < 0.25 ? 'square' : 'sawtooth' });
|
||||||
|
t += dur + 0.025 + rnd() * 0.05;
|
||||||
|
tom = Math.max(330, Math.min(1000, para * (0.9 + rnd() * 0.25)));
|
||||||
|
}
|
||||||
|
return t - c.currentTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
function tocar(c, nome, v) {
|
||||||
|
const f = SONS[nome];
|
||||||
|
if (!f || !c) return false;
|
||||||
|
f(c, c.currentTime + 0.02, v);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
window.VozRobo = { tocar, balbuciar, servo: (c, dur, v) => servo(c, c.currentTime + 0.01, dur, v), sons: Object.keys(SONS) };
|
||||||
|
})();
|
||||||
@@ -11,6 +11,7 @@
|
|||||||
<div id="app"></div>
|
<div id="app"></div>
|
||||||
<!-- mesmo motor de rosto do celular, usado nas miniaturas das reações -->
|
<!-- mesmo motor de rosto do celular, usado nas miniaturas das reações -->
|
||||||
<script src="/rosto-motor.js"></script>
|
<script src="/rosto-motor.js"></script>
|
||||||
|
<script src="/voz-robo.js"></script>
|
||||||
<script type="module" src="/src/main.ts"></script>
|
<script type="module" src="/src/main.ts"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -42,6 +42,11 @@
|
|||||||
enviar({ tipo: 'ordem', ordem: texto });
|
enviar({ tipo: 'ordem', ordem: texto });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Mostra uma legenda na faixa de baixo da prévia. */
|
||||||
|
export function legenda(texto: string) {
|
||||||
|
enviar({ tipo: 'legenda', texto });
|
||||||
|
}
|
||||||
|
|
||||||
/** Para a tela de reações: mostra uma receita sem mandar ao celular. */
|
/** Para a tela de reações: mostra uma receita sem mandar ao celular. */
|
||||||
export function previa(receita: unknown) {
|
export function previa(receita: unknown) {
|
||||||
enviar({ tipo: 'previa-reacao', receita });
|
enviar({ tipo: 'previa-reacao', receita });
|
||||||
|
|||||||
@@ -7,7 +7,23 @@
|
|||||||
import Toggle from '../lib/componentes/Toggle.svelte';
|
import Toggle from '../lib/componentes/Toggle.svelte';
|
||||||
import { estado } from '../lib/estado.svelte';
|
import { estado } from '../lib/estado.svelte';
|
||||||
|
|
||||||
let previa = $state<{ ordem: (t: string) => void }>();
|
let previa = $state<{ ordem: (t: string) => void; legenda: (t: string) => void }>();
|
||||||
|
// Ouvir a voz de robô aqui no PC (o clique na tecla libera o áudio do navegador).
|
||||||
|
let ouvirAqui = $state(true);
|
||||||
|
let audio: AudioContext | null = null;
|
||||||
|
function voz(): AudioContext | null {
|
||||||
|
const AC = window.AudioContext || (window as any).webkitAudioContext;
|
||||||
|
if (!ouvirAqui || !AC || !(window as any).VozRobo) return null;
|
||||||
|
audio ??= new AC();
|
||||||
|
if (audio.state === 'suspended') audio.resume();
|
||||||
|
return audio;
|
||||||
|
}
|
||||||
|
const FRASE = 'Oi! Eu sou o Carinha. Quer brincar comigo?';
|
||||||
|
function testarFala() {
|
||||||
|
previa?.legenda(FRASE);
|
||||||
|
const c = voz();
|
||||||
|
if (c) (window as any).VozRobo.balbuciar(c, FRASE, 0.5);
|
||||||
|
}
|
||||||
// Por padrão as emoções só aparecem aqui na prévia; ligado, vão também para o celular.
|
// Por padrão as emoções só aparecem aqui na prévia; ligado, vão também para o celular.
|
||||||
let noCelular = $state(false);
|
let noCelular = $state(false);
|
||||||
|
|
||||||
@@ -22,6 +38,8 @@
|
|||||||
function emocao(g: string) {
|
function emocao(g: string) {
|
||||||
if (noCelular) gesto(g);
|
if (noCelular) gesto(g);
|
||||||
else previa?.ordem(g);
|
else previa?.ordem(g);
|
||||||
|
const c = voz();
|
||||||
|
if (c) (window as any).VozRobo.tocar(c, g, 0.5);
|
||||||
}
|
}
|
||||||
|
|
||||||
const IDEIAS: { titulo: string; texto: string; feito: boolean; onde: string }[] = [
|
const IDEIAS: { titulo: string; texto: string; feito: boolean; onde: string }[] = [
|
||||||
@@ -30,6 +48,7 @@
|
|||||||
{ titulo: 'Toque na tela', texto: 'Cutucar dá susto e risada; deslizar o dedo é carinho; tocar acorda.', feito: true, onde: 'rosto' },
|
{ titulo: 'Toque na tela', texto: 'Cutucar dá susto e risada; deslizar o dedo é carinho; tocar acorda.', feito: true, onde: 'rosto' },
|
||||||
{ titulo: 'Mãos', texto: 'Mãozinhas na cor dos olhos: esconde o rosto, espia, acena e pensa com a mão no queixo.', feito: true, onde: 'rosto' },
|
{ titulo: 'Mãos', texto: 'Mãozinhas na cor dos olhos: esconde o rosto, espia, acena e pensa com a mão no queixo.', feito: true, onde: 'rosto' },
|
||||||
{ titulo: 'Faixa de baixo', texto: 'Legenda da conversa sendo digitada, pontinhos enquanto pensa, equalizador ao dançar e carga quando está no carregador.', feito: true, onde: 'rosto' },
|
{ titulo: 'Faixa de baixo', texto: 'Legenda da conversa sendo digitada, pontinhos enquanto pensa, equalizador ao dançar e carga quando está no carregador.', feito: true, onde: 'rosto' },
|
||||||
|
{ titulo: 'Voz de robô', texto: 'Chilreios, “uou!”, “ohh” e um balbucio quando responde, sintetizados na hora; motorzinho quando as mãos se mexem.', feito: true, onde: 'rosto' },
|
||||||
{ titulo: 'Fala pelo próprio celular', texto: 'A resposta da conversa sai no alto-falante do S10, com os olhos pulsando na voz.', feito: false, onde: 'app' },
|
{ titulo: 'Fala pelo próprio celular', texto: 'A resposta da conversa sai no alto-falante do S10, com os olhos pulsando na voz.', feito: false, onde: 'app' },
|
||||||
{ titulo: 'Ritmo do dia', texto: 'Boceja à noite, fica sonolento com bateria baixa, mostra um raio quando carrega.', feito: false, onde: 'rosto e servidor' },
|
{ titulo: 'Ritmo do dia', texto: 'Boceja à noite, fica sonolento com bateria baixa, mostra um raio quando carrega.', feito: false, onde: 'rosto e servidor' },
|
||||||
{ titulo: 'Contato visual', texto: 'Sustenta o olhar de quem a câmera vê e desvia quando fica tímido.', feito: false, onde: 'rosto' },
|
{ titulo: 'Contato visual', texto: 'Sustenta o olhar de quem a câmera vê e desvia quando fica tímido.', feito: false, onde: 'rosto' },
|
||||||
@@ -59,6 +78,15 @@
|
|||||||
<button class="tecla" onclick={() => emocao(g)}>{GESTOS_INFO[g].emoji} {GESTOS_INFO[g].nome}</button>
|
<button class="tecla" onclick={() => emocao(g)}>{GESTOS_INFO[g].emoji} {GESTOS_INFO[g].nome}</button>
|
||||||
{/each}
|
{/each}
|
||||||
</div>
|
</div>
|
||||||
|
<div class="linha">
|
||||||
|
<button class="tecla" onclick={testarFala}>🗣️ Testar fala</button>
|
||||||
|
</div>
|
||||||
|
<Toggle
|
||||||
|
rotulo="Ouvir a voz de robô aqui no PC"
|
||||||
|
ajuda="Sons sintetizados na hora, inspirados nos robozinhos de cinema"
|
||||||
|
checked={ouvirAqui}
|
||||||
|
onchange={(v) => (ouvirAqui = v)}
|
||||||
|
/>
|
||||||
<Toggle
|
<Toggle
|
||||||
rotulo="Mandar as emoções também para o celular"
|
rotulo="Mandar as emoções também para o celular"
|
||||||
ajuda="Desligado, elas aparecem só na prévia"
|
ajuda="Desligado, elas aparecem só na prévia"
|
||||||
|
|||||||
+1
-1
@@ -6,7 +6,7 @@ import { svelte } from '@sveltejs/vite-plugin-svelte';
|
|||||||
const alvo = process.env.CARINHA_SERVIDOR || 'http://127.0.0.1:8100';
|
const alvo = process.env.CARINHA_SERVIDOR || 'http://127.0.0.1:8100';
|
||||||
const api = ['/eventos', '/estado', '/comando', '/parar-tudo', '/rearmar', '/fila', '/config', '/faces', '/gestos',
|
const api = ['/eventos', '/estado', '/comando', '/parar-tudo', '/rearmar', '/fila', '/config', '/faces', '/gestos',
|
||||||
'/app', '/rtc', '/camera', '/conversa', '/treinamento', '/braco', '/servos', '/ia', '/api', '/gesto', '/face',
|
'/app', '/rtc', '/camera', '/conversa', '/treinamento', '/braco', '/servos', '/ia', '/api', '/gesto', '/face',
|
||||||
'/carinha.html', '/reacoes-render.js', '/rosto-motor.js', '/rastreador-worker.js', '/vendor', '/qualidade-auto.js', '/app.apk'];
|
'/carinha.html', '/reacoes-render.js', '/rosto-motor.js', '/voz-robo.js', '/rastreador-worker.js', '/vendor', '/qualidade-auto.js', '/app.apk'];
|
||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
plugins: [svelte()],
|
plugins: [svelte()],
|
||||||
|
|||||||
Reference in New Issue
Block a user