Skip to content

Commit

Permalink
fix transcription confidence must > 0,5
Browse files Browse the repository at this point in the history
  • Loading branch information
xqsadness committed Sep 19, 2023
1 parent 36202a1 commit 143e566
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = "ru"
language = "en"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
</constraints>
</imageView>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" misplaced="YES" text="Quiz App" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="DyQ-ie-krj">
<rect key="frame" x="130" y="474" width="132" height="48"/>
<rect key="frame" x="130" y="482" width="132" height="48"/>
<constraints>
<constraint firstAttribute="height" relation="greaterThanOrEqual" constant="48" id="B8B-I9-O1Y"/>
<constraint firstAttribute="width" relation="greaterThanOrEqual" constant="222" id="YWW-zZ-ifn"/>
Expand Down
11 changes: 11 additions & 0 deletions DefaultProject/DEFAULT_SOURCE/DefaultView/LoginDefaultView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ struct LoginDefaultView: View {
@StateObject var appController = APPCONTROLLER.shared
@StateObject var authManagerViewModel = AuthManagerViewModel.shared
@EnvironmentObject var coordinator: Coordinator
@FocusState private var focusedField: FocusedField?
@State var name: String = ""

enum FocusedField {
case username, password
}

var body: some View {
VStack{
Expand All @@ -30,6 +36,7 @@ struct LoginDefaultView: View {
}
.keyboardType(.emailAddress)
.foregroundColor(.background)
.focused($focusedField, equals: .username)
}
.padding(16)
.background(Color.gray.opacity(0.1))
Expand All @@ -43,13 +50,15 @@ struct LoginDefaultView: View {
}
.font(.regular(size: 15))
.foregroundColor(.background)
.focused($focusedField, equals: .password)
} else {
SecureField("Password ...", text: $authManagerViewModel.pswd)
.placeholder(when: authManagerViewModel.pswd.isEmpty) {
Text("Password").foregroundColor(.gray)
}
.font(.regular(size: 15))
.foregroundColor(.background)
.focused($focusedField, equals: .password)
}

Button(action: {
Expand All @@ -68,6 +77,7 @@ struct LoginDefaultView: View {

Button(action: {
if authManagerViewModel.isSignin{
focusedField = nil
authManagerViewModel.login()
}else{
authManagerViewModel.registerUser()
Expand Down Expand Up @@ -106,6 +116,7 @@ struct LoginDefaultView: View {
.background(Color.text)
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(Color.text)
.ignoresSafeArea(.keyboard)
.overlay {
LoadingView(show: $authManagerViewModel.isLoading)
}
Expand Down
27 changes: 25 additions & 2 deletions DefaultProject/View/CreateUsernameView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,19 @@ import SwiftUI

struct CreateUsernameView: View {
@AppStorage("Language") var language: String = "en"
@State var name: String = ""
@EnvironmentObject var coordinator: Coordinator
@FocusState private var focusedField: FocusedField?
@State var name: String = ""

enum FocusedField {
case name
}

var body: some View {
VStack{
HStack{
Button {
focusedField = nil
coordinator.pop()
} label: {
Image(systemName: "chevron.left")
Expand All @@ -30,7 +36,7 @@ struct CreateUsernameView: View {
Spacer()
}
.padding(.horizontal)

VStack{
Text("Quiz kid app")
.font(.bold(size: 22))
Expand Down Expand Up @@ -59,6 +65,18 @@ struct CreateUsernameView: View {
TextField("", text: $name)
.foregroundColor(Color.text2)
.padding(.horizontal)
.focused($focusedField, equals: .name)
.onSubmit {
if name.isEmpty || name.count < 2 || name.count > 18{
LocalNotification.shared.message("Name must be >= 2, <= 18 characters", .warning)
}else{
focusedField = nil
User.shared.userEmail = name
if User.shared.userEmail != "" {
coordinator.push(.homeView)
}
}
}
}
.overlay(
RoundedRectangle(cornerRadius: 6)
Expand All @@ -82,6 +100,7 @@ struct CreateUsernameView: View {
if name.isEmpty || name.count < 2 || name.count > 18{
LocalNotification.shared.message("Name must be >= 2, <= 18 characters", .warning)
}else{
focusedField = nil
User.shared.userEmail = name
if User.shared.userEmail != "" {
coordinator.push(.homeView)
Expand All @@ -100,5 +119,9 @@ struct CreateUsernameView: View {
.hAlign(.center)
.vAlign(.top)
.background(Color.accentColor)
.onAppear{
focusedField = .name
}
.ignoresSafeArea(.keyboard)
}
}
1 change: 1 addition & 0 deletions DefaultProject/View/Writing/QuizWritingContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ struct QuizWritingContentView: View {
RoundedRectangle(cornerRadius: 10)
.stroke(Color.text2, lineWidth: 2)
.opacity(selectedTab == CONSTANT.SHARED.DATA_WRITING.count - 1 && (countWrong + countCorrect == CONSTANT.SHARED.DATA_WRITING.count) ? 0.6 : 1)
.contentShape(Rectangle())
.simultaneousGesture(DragGesture())
}
.padding(.horizontal)
Expand Down
3 changes: 3 additions & 0 deletions DefaultProject/View/Writing/WritingView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import Speech
enum FocusedField {
case textWriting
}

struct WritingView: View {
@AppStorage("Language") var language: String = "en"
@EnvironmentObject var coordinator: Coordinator
Expand Down Expand Up @@ -61,6 +62,8 @@ struct WritingView: View {
}
})
}
.contentShape(Rectangle())
.simultaneousGesture(DragGesture())
}
}
.tabViewStyle(.page(indexDisplayMode: .never))
Expand Down
17 changes: 14 additions & 3 deletions DefaultProject/ViewModel/SpeechRecognizer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,20 @@ class SpeechRecognizer: ObservableObject {
}

if let result = result {
self.speak(result.bestTranscription.formattedString)

print(result.bestTranscription.segments)
// self.speak(result.bestTranscription.formattedString)

var bestTranscription: SFTranscription?

for transcription in result.transcriptions {
//find the largest confidence value and confidence > 0.5
if let bestSegment = transcription.segments.max(by: { $0.confidence < $1.confidence }), bestSegment.confidence > 0.5 {
bestTranscription = transcription
}
}

if let bestTranscription = bestTranscription {
self.speak(bestTranscription.formattedString)
}
}
}
} catch {
Expand Down

0 comments on commit 143e566

Please sign in to comment.