Skip to content

Commit 36785e0

Browse files
committed
Transcriber updates
1 parent e1c94ee commit 36785e0

File tree

3 files changed

+24
-24
lines changed

3 files changed

+24
-24
lines changed

Package.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ let package = Package(
88
products: [.library(name: "CompilerSwiftAI", targets: ["CompilerSwiftAI"])],
99
dependencies: [
1010
.package(url: "https://github.com/gonzalezreal/swift-markdown-ui", from: "2.4.1"),
11-
.package(url: "https://github.com/Compiler-Inc/SpeechRecognitionService", from: "0.1.0")
11+
.package(url: "https://github.com/Compiler-Inc/Transcriber", branch: "main")
1212
],
1313
targets: [
14-
.target(name: "CompilerSwiftAI", dependencies: ["SpeechRecognitionService", .product(name: "MarkdownUI", package: "swift-markdown-ui")] ),
14+
.target(name: "CompilerSwiftAI", dependencies: ["Transcriber", .product(name: "MarkdownUI", package: "swift-markdown-ui")] ),
1515
.testTarget(name: "CompilerSwiftAITests", dependencies: ["CompilerSwiftAI"]),
1616
]
1717
)

Sources/CompilerSwiftAI/UI/Chat/ChatView/ChatViewModel.swift

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import SwiftUI
22
import Speech
3-
import SpeechRecognitionService
3+
import Transcriber
44

55
import OSLog
66

@@ -11,24 +11,24 @@ let defaultSystemPrompt: String = """
1111

1212
@MainActor
1313
@Observable
14-
class ChatViewModel: SpeechRecognitionManaging {
14+
class ChatViewModel: Transcribable {
1515

1616
public var isRecording = false
1717
public var transcribedText = ""
1818
public var authStatus: SFSpeechRecognizerAuthorizationStatus = .notDetermined
1919
public var error: Error?
2020

21-
public let speechService: SpeechRecognitionService?
21+
public let transcriber: Transcriber?
2222
private var recordingTask: Task<Void, Never>?
2323

2424
// Required protocol methods
2525
public func requestAuthorization() async throws {
26-
guard let speechService else {
27-
throw SpeechRecognitionError.noRecognizer
26+
guard let transcriber else {
27+
throw TranscriberError.noRecognizer
2828
}
29-
authStatus = await speechService.requestAuthorization()
29+
authStatus = await transcriber.requestAuthorization()
3030
guard authStatus == .authorized else {
31-
throw SpeechRecognitionError.notAuthorized
31+
throw TranscriberError.notAuthorized
3232
}
3333
}
3434

@@ -78,7 +78,7 @@ class ChatViewModel: SpeechRecognitionManaging {
7878
init(client: CompilerClient, systemPrompt: String = defaultSystemPrompt) {
7979
self.client = client
8080
self.systemPrompt = systemPrompt
81-
self.speechService = SpeechRecognitionService(config: DefaultSpeechConfig())
81+
self.transcriber = Transcriber()
8282

8383
self.chatHistory = ChatHistory(systemPrompt: systemPrompt)
8484

@@ -90,8 +90,8 @@ class ChatViewModel: SpeechRecognitionManaging {
9090
}
9191

9292
func toggleRecording() {
93-
guard let speechService else {
94-
error = SpeechRecognitionError.noRecognizer
93+
guard let transcriber else {
94+
error = TranscriberError.noRecognizer
9595
return
9696
}
9797

@@ -102,7 +102,7 @@ class ChatViewModel: SpeechRecognitionManaging {
102102
} else {
103103
recordingTask = Task {
104104
do {
105-
let stream = try await speechService.startRecordingStream()
105+
let stream = try await transcriber.startRecordingStream()
106106
isRecording = true
107107

108108
for try await partialResult in stream {

Sources/CompilerSwiftAI/UI/Function Chat/FunctionChatViewModel.swift

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,33 @@
22

33
import SwiftUI
44
import Speech
5-
import SpeechRecognitionService
5+
import Transcriber
66

77
@MainActor
88
@Observable
9-
class FunctionChatViewModel<AppState: Encodable & Sendable, Parameters: Decodable & Sendable>: SpeechRecognitionManaging {
9+
class FunctionChatViewModel<AppState: Encodable & Sendable, Parameters: Decodable & Sendable>: Transcribable {
1010
public var isRecording = false
1111
public var transcribedText = ""
1212
public var authStatus: SFSpeechRecognizerAuthorizationStatus = .notDetermined
1313
public var error: Error?
1414

15-
public let speechService: SpeechRecognitionService?
15+
public let transcriber: Transcriber?
1616
private var recordingTask: Task<Void, Never>?
1717

1818
// Required protocol methods
1919
public func requestAuthorization() async throws {
20-
guard let speechService else {
21-
throw SpeechRecognitionError.noRecognizer
20+
guard let transcriber else {
21+
throw TranscriberError.noRecognizer
2222
}
23-
authStatus = await speechService.requestAuthorization()
23+
authStatus = await transcriber.requestAuthorization()
2424
guard authStatus == .authorized else {
25-
throw SpeechRecognitionError.notAuthorized
25+
throw TranscriberError.notAuthorized
2626
}
2727
}
2828

2929
public func toggleRecording() {
30-
guard let speechService else {
31-
error = SpeechRecognitionError.noRecognizer
30+
guard let transcriber else {
31+
error = TranscriberError.noRecognizer
3232
return
3333
}
3434

@@ -40,7 +40,7 @@ class FunctionChatViewModel<AppState: Encodable & Sendable, Parameters: Decodabl
4040
recordingTask = Task {
4141
do {
4242
isRecording = true
43-
let stream = try await speechService.startRecordingStream()
43+
let stream = try await transcriber.startRecordingStream()
4444

4545
for try await transcription in stream {
4646
inputText = transcription
@@ -65,7 +65,7 @@ class FunctionChatViewModel<AppState: Encodable & Sendable, Parameters: Decodabl
6565

6666

6767
init(state: AppState, client: CompilerClient, describe: @escaping (Function<Parameters>) -> String, execute: @escaping (Function<Parameters>) -> Void) {
68-
self.speechService = SpeechRecognitionService(config: DefaultSpeechConfig())
68+
self.transcriber = Transcriber()
6969
self.state = state
7070
self.client = client
7171
self.describe = describe

0 commit comments

Comments
 (0)