fix(audio): kurze TTS — Padding auf 3s erhoeht (OnePlus A12 Hard-Threshold)
Test mit 96000B (2s) Padding zeigte: AudioTrack stallt immer noch mit pos=0/48000. Ab 8 Worten (~2.5s) geht's — der Hard-Threshold liegt also zwischen 2s und 3s. Padding auf 3s, Buffer auf 4s. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -79,13 +79,11 @@ class PcmStreamPlayerModule(reactContext: ReactApplicationContext) : ReactContex
|
|||||||
val minBuf = AudioTrack.getMinBufferSize(sampleRate, channelConfig, encoding)
|
val minBuf = AudioTrack.getMinBufferSize(sampleRate, channelConfig, encoding)
|
||||||
val bytesPerSecond = sampleRate * channels * 2 // 16-bit = 2 bytes
|
val bytesPerSecond = sampleRate * channels * 2 // 16-bit = 2 bytes
|
||||||
val prerollTarget = (bytesPerSecond * prerollSec).toInt()
|
val prerollTarget = (bytesPerSecond * prerollSec).toInt()
|
||||||
// Buffer entkoppelt von Preroll — fester ~3s-Buffer reicht. Wenn er
|
// Buffer entkoppelt von Preroll — fester ~4s-Buffer. OnePlus A12
|
||||||
// an Preroll gekoppelt ist (z.B. 7s bei preroll=3.5s) und nur kurz
|
// mit USAGE_ASSISTANT laeuft AudioTrack erst ab ~3s gepufferter
|
||||||
// gefuettert wird, stallt AudioTrack auf manchen Geraeten (OnePlus
|
// Daten an. Wir padden Kurztexte vor play() auf 3s (siehe Block
|
||||||
// Android 12: pos bleibt 0 obwohl play() lief).
|
// nach mainLoop), Buffer braucht ~1s Headroom weil write() blockt.
|
||||||
// 3s damit Padding bis 2s vor play() noch Headroom hat (write() ist
|
val bufferSize = (bytesPerSecond * 4).coerceAtLeast(minBuf * 8)
|
||||||
// blocking — wenn Buffer voll ist, deadlockt es vor play()).
|
|
||||||
val bufferSize = (bytesPerSecond * 3).coerceAtLeast(minBuf * 8)
|
|
||||||
prerollBytes = prerollTarget
|
prerollBytes = prerollTarget
|
||||||
bytesBuffered = 0
|
bytesBuffered = 0
|
||||||
playbackStarted = false
|
playbackStarted = false
|
||||||
@@ -229,10 +227,11 @@ class PcmStreamPlayerModule(reactContext: ReactApplicationContext) : ReactContex
|
|||||||
bytesBuffered += silence.size
|
bytesBuffered += silence.size
|
||||||
}
|
}
|
||||||
// Bei kurzem Text (play() noch nicht gestartet): Buffer auf min.
|
// Bei kurzem Text (play() noch nicht gestartet): Buffer auf min.
|
||||||
// 2s padden + DANN play(). Auf OnePlus A12 startet AudioTrack
|
// 3s padden + DANN play(). Auf OnePlus A12 startet AudioTrack
|
||||||
// bei einem zu duennen Buffer nicht — pos bleibt auf 0 stehen.
|
// bei < 3s Buffer-Inhalt nicht — pos bleibt auf 0 stehen.
|
||||||
|
// (2s war zu wenig, 8 Worte ~2.5s gingen, 3 Worte ~1s nicht.)
|
||||||
if (!playbackStarted && !writerShouldStop) {
|
if (!playbackStarted && !writerShouldStop) {
|
||||||
val minStartBytes = bytesPerSecond * 2
|
val minStartBytes = bytesPerSecond * 3
|
||||||
if (bytesBuffered < minStartBytes) {
|
if (bytesBuffered < minStartBytes) {
|
||||||
val padBytes = (minStartBytes - bytesBuffered.toInt()) and 0x7FFFFFFE
|
val padBytes = (minStartBytes - bytesBuffered.toInt()) and 0x7FFFFFFE
|
||||||
val pad = ByteArray(padBytes)
|
val pad = ByteArray(padBytes)
|
||||||
|
|||||||
Reference in New Issue
Block a user