Skip to content

Instantly share code, notes, and snippets.

@wizard1066
Created November 1, 2022 10:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wizard1066/5732ddbefac542247d704f0e1f69edec to your computer and use it in GitHub Desktop.
Save wizard1066/5732ddbefac542247d704f0e1f69edec to your computer and use it in GitHub Desktop.
struct ContentView: View {
@State private var sourceType: UIImagePickerController.SourceType = .camera
@State private var selectedImage: UIImage?
@State private var isImagePickerDisplay = false
@State private var sync2 = speaking()
@State var strings:[String] = []
var body: some View {
NavigationView {
VStack {
if selectedImage != nil {
Image(uiImage: selectedImage!)
.resizable()
.aspectRatio(contentMode: .fit)
.clipShape(Circle())
.frame(width: 512, height: 512)
.onTapGesture {
scanText()
sync2.speaker(words: strings)
}
} else {
Image(systemName: "camera")
.resizable()
.aspectRatio(contentMode: .fit)
.clipShape(Circle())
.frame(width: 512, height: 512)
}
HStack {
Button("Camera") {
self.strings.removeAll()
self.sourceType = .camera
self.isImagePickerDisplay.toggle()
}.padding()
Button("photo") {
self.strings.removeAll()
self.sourceType = .photoLibrary
self.isImagePickerDisplay.toggle()
}.padding()
}
}
.navigationBarTitle("Demo")
.sheet(isPresented: self.$isImagePickerDisplay) {
ImagePickerView(selectedImage: self.$selectedImage, sourceType: self.sourceType)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment