Spaces:
Running
Running
Update flare-ui/src/app/services/audio-stream.service.ts
Browse files
flare-ui/src/app/services/audio-stream.service.ts
CHANGED
@@ -136,19 +136,54 @@ export class AudioStreamService implements OnDestroy {
|
|
136 |
this.source = this.audioContext.createMediaStreamSource(this.audioStream!);
|
137 |
|
138 |
// Create script processor for raw PCM access
|
139 |
-
// Buffer size: 4096 samples, 1 input channel, 1 output channel
|
140 |
this.scriptProcessor = this.audioContext.createScriptProcessor(4096, 1, 1);
|
141 |
|
|
|
|
|
|
|
142 |
this.scriptProcessor.onaudioprocess = (audioEvent) => {
|
143 |
// Get PCM data from input buffer
|
144 |
const inputData = audioEvent.inputBuffer.getChannelData(0);
|
145 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
146 |
// Convert Float32Array to Int16Array (Linear16)
|
147 |
const pcmData = this.float32ToInt16(inputData);
|
148 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
149 |
// Convert to base64
|
150 |
const base64Data = this.arrayBufferToBase64(pcmData.buffer);
|
151 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
152 |
// Send chunk
|
153 |
this.audioChunkSubject.next({
|
154 |
data: base64Data,
|
@@ -160,6 +195,14 @@ export class AudioStreamService implements OnDestroy {
|
|
160 |
this.source.connect(this.scriptProcessor);
|
161 |
this.scriptProcessor.connect(this.audioContext.destination);
|
162 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
163 |
console.log('✅ Linear16 recording setup complete');
|
164 |
}
|
165 |
|
|
|
136 |
this.source = this.audioContext.createMediaStreamSource(this.audioStream!);
|
137 |
|
138 |
// Create script processor for raw PCM access
|
|
|
139 |
this.scriptProcessor = this.audioContext.createScriptProcessor(4096, 1, 1);
|
140 |
|
141 |
+
// Debug için chunk counter
|
142 |
+
let chunkCounter = 0;
|
143 |
+
|
144 |
this.scriptProcessor.onaudioprocess = (audioEvent) => {
|
145 |
// Get PCM data from input buffer
|
146 |
const inputData = audioEvent.inputBuffer.getChannelData(0);
|
147 |
|
148 |
+
// Debug: İlk 5 chunk için detaylı log
|
149 |
+
if (chunkCounter < 5) {
|
150 |
+
const maxAmplitude = Math.max(...inputData.map(Math.abs));
|
151 |
+
const avgAmplitude = inputData.reduce((sum, val) => sum + Math.abs(val), 0) / inputData.length;
|
152 |
+
|
153 |
+
console.log(`🎤 Audio Debug Chunk #${chunkCounter}:`, {
|
154 |
+
bufferLength: inputData.length,
|
155 |
+
maxAmplitude: maxAmplitude.toFixed(6),
|
156 |
+
avgAmplitude: avgAmplitude.toFixed(6),
|
157 |
+
firstSamples: Array.from(inputData.slice(0, 10)).map(v => v.toFixed(4)),
|
158 |
+
silent: maxAmplitude < 0.001
|
159 |
+
});
|
160 |
+
}
|
161 |
+
|
162 |
// Convert Float32Array to Int16Array (Linear16)
|
163 |
const pcmData = this.float32ToInt16(inputData);
|
164 |
|
165 |
+
// Debug: PCM dönüşümünü kontrol et
|
166 |
+
if (chunkCounter < 5) {
|
167 |
+
const pcmArray = Array.from(pcmData.slice(0, 10));
|
168 |
+
console.log(`🔄 PCM Conversion #${chunkCounter}:`, {
|
169 |
+
firstPCMSamples: pcmArray,
|
170 |
+
maxPCM: Math.max(...Array.from(pcmData).map(Math.abs))
|
171 |
+
});
|
172 |
+
}
|
173 |
+
|
174 |
// Convert to base64
|
175 |
const base64Data = this.arrayBufferToBase64(pcmData.buffer);
|
176 |
|
177 |
+
// Debug: Base64 çıktısını kontrol et
|
178 |
+
if (chunkCounter < 5) {
|
179 |
+
console.log(`📦 Base64 Output #${chunkCounter}:`, {
|
180 |
+
base64Length: base64Data.length,
|
181 |
+
base64Preview: base64Data.substring(0, 50) + '...'
|
182 |
+
});
|
183 |
+
}
|
184 |
+
|
185 |
+
chunkCounter++;
|
186 |
+
|
187 |
// Send chunk
|
188 |
this.audioChunkSubject.next({
|
189 |
data: base64Data,
|
|
|
195 |
this.source.connect(this.scriptProcessor);
|
196 |
this.scriptProcessor.connect(this.audioContext.destination);
|
197 |
|
198 |
+
// Test: Mikrofon seviyesini kontrol et
|
199 |
+
setTimeout(() => {
|
200 |
+
if (this.source && this.audioContext) {
|
201 |
+
console.log('🎙️ Audio Context State:', this.audioContext.state);
|
202 |
+
console.log('🎙️ Sample Rate:', this.audioContext.sampleRate);
|
203 |
+
}
|
204 |
+
}, 1000);
|
205 |
+
|
206 |
console.log('✅ Linear16 recording setup complete');
|
207 |
}
|
208 |
|