Skip to content

Commit 32e6113

Browse files
committed
Formatting and adding typealias
1 parent 78f5bab commit 32e6113

File tree

6 files changed

+24
-11
lines changed

6 files changed

+24
-11
lines changed

Playground.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
7446C9172E4D536400290EAB /* SwiftUI.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7446C9162E4D536400290EAB /* SwiftUI.framework */; };
2525
7446C9242E4D536500290EAB /* TranscriptionLiveActivityExtension.appex in Embed Foundation Extensions */ = {isa = PBXBuildFile; fileRef = 7446C9122E4D536400290EAB /* TranscriptionLiveActivityExtension.appex */; platformFilter = ios; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
2626
7469F1FA2E3AC3D00090AEBA /* README.md in Resources */ = {isa = PBXBuildFile; fileRef = 7469F1F92E3AC3D00090AEBA /* README.md */; };
27+
746D9D512EC7D12300CBFB4A /* VocabularyResults.swift in Sources */ = {isa = PBXBuildFile; fileRef = 746D9D502EC7D11E00CBFB4A /* VocabularyResults.swift */; };
2728
746E4C062E39874F009623D7 /* DefaultEnvInitializer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 746E4C042E39874F009623D7 /* DefaultEnvInitializer.swift */; };
2829
746E4C0A2E398757009623D7 /* PlaygroundEnvInitializer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 746E4C082E398757009623D7 /* PlaygroundEnvInitializer.swift */; };
2930
746F2A072E39D7030081D0D6 /* NoOpAnalyticsLogger.swift in Sources */ = {isa = PBXBuildFile; fileRef = 746F2A062E39D6FC0081D0D6 /* NoOpAnalyticsLogger.swift */; };
@@ -103,6 +104,7 @@
103104
7446C9142E4D536400290EAB /* WidgetKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = WidgetKit.framework; path = System/Library/Frameworks/WidgetKit.framework; sourceTree = SDKROOT; };
104105
7446C9162E4D536400290EAB /* SwiftUI.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SwiftUI.framework; path = System/Library/Frameworks/SwiftUI.framework; sourceTree = SDKROOT; };
105106
7469F1F92E3AC3D00090AEBA /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
107+
746D9D502EC7D11E00CBFB4A /* VocabularyResults.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VocabularyResults.swift; sourceTree = "<group>"; };
106108
746E4C042E39874F009623D7 /* DefaultEnvInitializer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DefaultEnvInitializer.swift; sourceTree = "<group>"; };
107109
746E4C082E398757009623D7 /* PlaygroundEnvInitializer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlaygroundEnvInitializer.swift; sourceTree = "<group>"; };
108110
746F2A062E39D6FC0081D0D6 /* NoOpAnalyticsLogger.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NoOpAnalyticsLogger.swift; sourceTree = "<group>"; };
@@ -272,6 +274,7 @@
272274
74C12F122E2EB54A00C772C3 /* Utils */ = {
273275
isa = PBXGroup;
274276
children = (
277+
746D9D502EC7D11E00CBFB4A /* VocabularyResults.swift */,
275278
74F860952E2B19060007163C /* CoreAudioUtils.swift */,
276279
);
277280
path = Utils;
@@ -404,6 +407,7 @@
404407
747E67082E300F780061E778 /* TranscribeResultView.swift in Sources */,
405408
74312CDC2E1D02E3000D994A /* MacAudioDevicesView.swift in Sources */,
406409
74F3B7BE2E1CF44F00C544D1 /* AudioProcessDiscoverer.swift in Sources */,
410+
746D9D512EC7D12300CBFB4A /* VocabularyResults.swift in Sources */,
407411
1677AFE62B57704E008C61C0 /* ContentView.swift in Sources */,
408412
74F3B7C12E1CF4F400C544D1 /* AudioProcess.swift in Sources */,
409413
746F2A072E39D7030081D0D6 /* NoOpAnalyticsLogger.swift in Sources */,
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import Argmax
2+
3+
/// Convenient alias used for mapping `WordTiming` values to their matching custom vocabulary hits.
4+
typealias VocabularyResults = [WordTiming: [WordTiming]]

Playground/ViewModels/StreamViewModel.swift

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ class StreamViewModel: ObservableObject {
144144
var title: String = ""
145145
var confirmedSegments: [TranscriptionSegment] = []
146146
var hypothesisSegments: [TranscriptionSegment] = []
147-
var customVocabularyResults: [WordTiming: [WordTiming]] = [:]
147+
var customVocabularyResults: VocabularyResults = [:]
148148
var streamEndSeconds: Float?
149149
var bufferEnergy: [Float] = []
150150
var streamTimestampText: String {
@@ -316,8 +316,8 @@ class StreamViewModel: ObservableObject {
316316
}
317317

318318
private func mergeVocabularyResults(
319-
existing: inout [WordTiming: [WordTiming]],
320-
newResults: [WordTiming: [WordTiming]]
319+
existing: inout VocabularyResults,
320+
newResults: VocabularyResults
321321
) {
322322
guard !newResults.isEmpty else { return }
323323
for (key, occurrences) in newResults {
@@ -333,7 +333,7 @@ class StreamViewModel: ObservableObject {
333333
@MainActor
334334
private func handleResult(_ result: LiveResult, for sourceId: String) {
335335
switch result {
336-
case .hypothesis(let text, _, let hypothesisResult):
336+
case .hypothesis(_, _, let hypothesisResult):
337337
let now = Date().timeIntervalSince1970
338338
let last = lastHypothesisUpdateAtBySource[sourceId] ?? 0
339339
// Update at most 10 times per second per source
@@ -354,7 +354,12 @@ class StreamViewModel: ObservableObject {
354354
Task {
355355
await liveActivityManager.updateContentState { oldState in
356356
var state = oldState
357-
let highlightedHypothesis = HighlightedTextView.createHighlightedAttributedString(segments: deviceResult?.hypothesisSegments ?? [], customVocabularyResults: deviceResult?.customVocabularyResults ?? [:], font: .body, foregroundColor: .primary)
357+
let highlightedHypothesis = HighlightedTextView.createHighlightedAttributedString(
358+
segments: deviceResult?.hypothesisSegments ?? [],
359+
customVocabularyResults: deviceResult?.customVocabularyResults ?? [:],
360+
font: .body,
361+
foregroundColor: .primary
362+
)
358363
state.currentHypothesis = highlightedHypothesis
359364
return state
360365
}

Playground/ViewModels/TranscribeViewModel.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class TranscribeViewModel: ObservableObject {
5757
@Published var bufferEnergy: [Float] = []
5858
@Published var confirmedSegments: [TranscriptionSegment] = []
5959
@Published var unconfirmedSegments: [TranscriptionSegment] = []
60-
@Published var customVocabularyResults: [WordTiming: [WordTiming]] = [:]
60+
@Published var customVocabularyResults: VocabularyResults = [:]
6161
@Published var showShortAudioToast: Bool = false
6262
@Published var diarizedSpeakerSegments: [SpeakerSegment] = []
6363
@Published var speakerNames: [Int: String] = [:]

Playground/Views/HighlightedTextView.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ import Argmax
66
struct HighlightedTextView: View {
77
let prefixText: String
88
let segments: [TranscriptionSegment]
9-
let customVocabularyResults: [WordTiming: [WordTiming]]
9+
let customVocabularyResults: VocabularyResults
1010
let font: Font
1111
let foregroundColor: Color
1212

1313
init(
1414
prefixText: String = "",
1515
segments: [TranscriptionSegment] = [],
16-
customVocabularyResults: [WordTiming: [WordTiming]] = [:],
16+
customVocabularyResults: VocabularyResults = [:],
1717
font: Font = .body,
1818
foregroundColor: Color = .primary
1919
) {
@@ -47,7 +47,7 @@ struct HighlightedTextView: View {
4747
static func createHighlightedAttributedString(
4848
prefixText: String = "",
4949
segments: [TranscriptionSegment] = [],
50-
customVocabularyResults: [WordTiming: [WordTiming]] = [:],
50+
customVocabularyResults: VocabularyResults = [:],
5151
font: Font,
5252
foregroundColor: Color
5353
) -> AttributedString {
@@ -129,7 +129,7 @@ struct HighlightedTextView: View {
129129
let sdkWord = WordTiming(word: "SDK", tokens: [], start: 1.0, end: 1.2, probability: 0.9)
130130
let developersWord = WordTiming(word: "developers", tokens: [], start: 1.2, end: 1.5, probability: 0.9)
131131

132-
let vocabulary: [WordTiming: [WordTiming]] = [
132+
let vocabulary: VocabularyResults = [
133133
helloWord: [helloWord],
134134
specialWord: [specialWord],
135135
sdkWord: [sdkWord],

Playground/Views/StreamResultView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ struct StreamResultLine: View {
1717

1818
let result: StreamViewModel.StreamResult
1919

20-
private func createHighlightedAttributedString(prefix: String = "", segments: [TranscriptionSegment], customVocabularyResults: [WordTiming: [WordTiming]] = [:], isBold: Bool, color: Color) -> AttributedString {
20+
private func createHighlightedAttributedString(prefix: String = "", segments: [TranscriptionSegment], customVocabularyResults: VocabularyResults = [:], isBold: Bool, color: Color) -> AttributedString {
2121
let baseFont: Font = isBold ? .headline.bold() : .headline
2222
return HighlightedTextView.createHighlightedAttributedString(
2323
prefixText: prefix,

0 commit comments

Comments
 (0)