知了 Cicada · 任何会议和直播的实时字幕、同声传译、AI 会议纪要,Mac、Windows、Linux、Android 免费开源。Live subtitles, interpreting and meeting notes for any call or stream, on Mac, Windows, Linux and Android.
Swift androidlinuxlive-captionsmacosmeeting-notesmenubar-appsimultaneous-interpretationspeech-recognitionsubtitlesswiftswiftuitranslationwindows
chore(android): show the sample's first line sooner and keep every line on 试一下
wqugurua288dea99a33
diff --git a/android/app/src/main/kotlin/com/wquguru/cicada/OnboardingActivity.kt b/android/app/src/main/kotlin/com/wquguru/cicada/OnboardingActivity.ktindex 68f2838..ca4d507 100644--- a/android/app/src/main/kotlin/com/wquguru/cicada/OnboardingActivity.kt+++ b/android/app/src/main/kotlin/com/wquguru/cicada/OnboardingActivity.kt@@ -273,19 +273,39 @@ class OnboardingActivity : Activity() {addView(progressClock, LinearLayout.LayoutParams(-2, -2).apply { leftMargin = ui.dp(12) })}val content = ui.stack(16, intro(L("试一下"), L("放一段 9 秒的示例会议,看看字幕和纪要怎么出来")), player)- val line = heard?.lines?.lastOrNull()+ val lines = heard?.lines.orEmpty()+ val line = lines.lastOrNull()if (line != null) {val card = NotesViews.liveCard(ui, app, line, 20f, dots = playing)card.addView(ui.text(L("字幕"), 13f, Palette.secondary, bold = true), 0)(card.getChildAt(1).layoutParams as? LinearLayout.LayoutParams)?.topMargin = ui.dp(10)+ // The lines before the newest stay above it: the sample's two come back half a second+ // apart, and showing only the newest made the first one flash by.+ lines.dropLast(1).takeLast(2).forEachIndexed { i, l ->+ val row = ui.stack(2, ui.text(NotesViews.said(l), 13f, Palette.secondary))+ if (!l.dst.isNullOrEmpty() && l.dst != l.src) row.addView(ui.text(l.dst!!, 15f, Palette.ink))+ card.addView(row, 1 + i, ui.lp(top = 10))+ }content.addView(card, ui.lp(top = 12))- val notes = heard.notes ?: if (app.notes.shownId == heard.id) app.notes.notes else null+ val notes = heard?.notes ?: if (app.notes.shownId == heard?.id) app.notes.notes else nullval notesCard = ui.stack(8, ui.text(L("纪要"), 13f, Palette.secondary, bold = true),NotesViews.notesBody(ui, notes ?: MeetingNotes(), app.notes.status, true, compact = true)).apply {background = ui.rounded(Palette.card, 20)setPadding(ui.dp(18), ui.dp(16), ui.dp(18), ui.dp(16))}content.addView(notesCard, ui.lp(top = 12))+ } else if (playing) {+ // Ming answers a stretch once it ends (~6 s in for the first): say it's coming.+ content.addView(ui.stack(10, ui.text(L("字幕"), 13f, Palette.secondary, bold = true),+ LinearLayout(this).apply {+ orientation = LinearLayout.HORIZONTAL+ gravity = Gravity.CENTER_VERTICAL+ listOf(1f, 0.6f, 0.3f).forEach { a -> addView(ui.dot(Palette.accent, 6).apply { alpha = a }, LinearLayout.LayoutParams(ui.dp(6), ui.dp(6)).apply { rightMargin = ui.dp(5) }) }+ addView(ui.text(L("正在听下一句…"), 15f, Palette.secondary), LinearLayout.LayoutParams(-2, -2).apply { leftMargin = ui.dp(4) })+ }).apply {+ background = ui.rounded(Palette.card, 20)+ setPadding(ui.dp(18), ui.dp(16), ui.dp(18), ui.dp(16))+ }, ui.lp(top = 12))} else {content.addView(LinearLayout(this).apply {layoutParams = ui.lp(top = 12)diff --git a/android/cli/src/main/kotlin/cicada/cli/Tests.kt b/android/cli/src/main/kotlin/cicada/cli/Tests.ktindex a556231..0f17454 100644--- a/android/cli/src/main/kotlin/cicada/cli/Tests.kt+++ b/android/cli/src/main/kotlin/cicada/cli/Tests.kt@@ -34,6 +34,7 @@ object Tests {"joinsCutSentences" to ::joinsCutSentences,"segmentsOnPauses" to ::segmentsOnPauses,"cutsLongSpeechAtItsQuietestMoment" to ::cutsLongSpeech,+ "cutsTheFirstStretchEarly" to ::cutsTheFirstStretchEarly,"ignoresClicks" to ::ignoresClicks,"wavRoundTrip" to ::wavRoundTrip,"parsesNotes" to ::parsesNotes,@@ -270,12 +271,20 @@ object Tests {}fun cutsLongSpeech() {- // 7 s of speech, a 0.3 s dip (shorter than a pause), 4 s more: one cut, at the dip.- val list = cut(tone(7.0), tone(0.3, 0.004), tone(4.0), silence(1.0))- equal(2, list.size, "split in two")- check(list[0].seconds in 6.9..7.4, "cut inside the dip, got ${list[0].seconds}")+ // After a first short stretch: 7 s of speech, a 0.3 s dip (shorter than a pause), 4 s+ // more: one cut, at the dip.+ val list = cut(tone(1.0), silence(1.0), tone(7.0), tone(0.3, 0.004), tone(4.0), silence(1.0))+ equal(3, list.size, "the first, then the long one split in two")+ check(list[1].seconds in 6.9..7.4, "cut inside the dip, got ${list[1].seconds}")check(list.all { it.seconds <= 8.0 }, "no segment over 8 s")- check(abs(list[1].start - (list[0].start + list[0].seconds)) < 0.001, "the rest carries on without a gap")+ check(abs(list[2].start - (list[1].start + list[1].seconds)) < 0.001, "the rest carries on without a gap")+ }++ fun cutsTheFirstStretchEarly() {+ // A meeting's first stretch is cut by 4 s (at its quietest moment), so a line shows soon.+ val list = cut(tone(3.0), tone(0.3, 0.004), tone(4.0), silence(1.0))+ equal(2, list.size, "split in two")+ check(list[0].seconds in 2.9..3.5, "cut inside the dip, got ${list[0].seconds}")}fun ignoresClicks() {diff --git a/android/core/src/main/kotlin/cicada/ListenEngine.kt b/android/core/src/main/kotlin/cicada/ListenEngine.ktindex 0bcc552..2ca929a 100644--- a/android/core/src/main/kotlin/cicada/ListenEngine.kt+++ b/android/core/src/main/kotlin/cicada/ListenEngine.kt@@ -169,6 +169,8 @@ class ListenEngine(/// final notes. Blocks until the record is saved: call off the main thread.fun stop() {if (!listening) return+ // This meeting's id now: a new one may start while this waits for Ming below.+ val id = sessionId ?: returnlistening = falsesource?.let { it.onSamples = null; it.stop() }audio?.offer(END)@@ -178,7 +180,6 @@ class ListenEngine(for (f in waiting) {try { f.get(maxOf(1, deadline - System.currentTimeMillis()), TimeUnit.MILLISECONDS) } catch (_: Exception) {}}- val id = sessionId ?: returnstore.end(id)Log.d("listen: stopped $id, $lineCount lines")changed()diff --git a/android/core/src/main/kotlin/cicada/Segmenter.kt b/android/core/src/main/kotlin/cicada/Segmenter.ktindex d3f9d30..a828c06 100644--- a/android/core/src/main/kotlin/cicada/Segmenter.kt+++ b/android/core/src/main/kotlin/cicada/Segmenter.kt@@ -8,8 +8,10 @@ class Segment(val index: Int, val start: Double, val samples: ShortArray) {/// Cuts the audio into stretches of speech by loudness alone: a pause of 0.6 s ends one, and one/// that runs to 8 s is cut at its quietest moment in the last 2 s, so a word is split as rarely as-/// possible (Ming has no word timings to put it back together). Not thread-safe: fed from the-/// listening worker only. Same numbers as the Windows Segmenter.+/// possible (Ming has no word timings to put it back together). The first stretch of a meeting is+/// cut at 4 s instead: with nothing on screen yet, a first line at ~6 s beats a whole sentence at+/// ~10 s, and ListenEngine joins the rest onto it. Not thread-safe: fed from the listening worker+/// only. Otherwise the same numbers as the Windows Segmenter.class Segmenter {companion object {const val RATE = 16000@@ -17,6 +19,7 @@ class Segmenter {@Volatile var threshold = 0.01 // the Mac AudioRouter's gate (about -40 dBFS)@Volatile var pause = 0.6@Volatile var maxLength = 8.0+ @Volatile var firstMaxLength = 4.0@Volatile var minSpeech = 0.25private const val PRE_ROLL = 0.15private const val TAIL = 0.15@@ -72,7 +75,7 @@ class Segmenter {if (quietFrames * FRAME >= pause * RATE) {close(current.size - quietFrames * FRAME + (TAIL * RATE).toInt())- } else if (current.size >= maxLength * RATE) {+ } else if (current.size >= (if (index == 0) firstMaxLength else maxLength) * RATE) {// The quietest frame in the last 2 s; the rest starts the next segment.val from = maxOf(1, levels.size - (CUT_WINDOW * RATE / FRAME).toInt())var cut = from