Skip to content

Instantly share code, notes, and snippets.

View dbolella's full-sized avatar

Daniel Bolella dbolella

View GitHub Profile
@dbolella
dbolella / Overlaying.swift
Last active September 4, 2019 19:17
Enhanced Overlay Control in SwiftUI
struct ContentView: View {
@State var showOverlay = false
@State var curColor = Color.blue
var body: some View {
Text("Hello World")
.frame(width: 100, height: 100)
.background(curColor)
.cornerRadius(20)
.onTapGesture { self.showOverlay.toggle() }
@dbolella
dbolella / OverlayControl.swift
Created September 4, 2019 17:32
Overlay control demo in SwiftUI
struct ContentView: View {
@State var textColor = Color.blue
@State var showOverlay = false
var body: some View {
Text("Hello World")
.frame(width: 100, height: 100)
.background(textColor)
.onTapGesture { self.showOverlay.toggle() }
.overlay(
@dbolella
dbolella / SetupSpeechRecognizer.swift
Last active September 30, 2019 19:01
Setting up SFSpeechRecognizer for Audio Buffers
private let speechRecognizer = SFSpeechRecognizer(locale: Locale(identifier: "en-US"))!
private var recognitionRequest: SFSpeechAudioBufferRecognitionRequest?
private var recognitionTask: SFSpeechRecognitionTask?
private func setupRecognition() {
let recognitionRequest = SFSpeechAudioBufferRecognitionRequest()
recognitionRequest.shouldReportPartialResults = true
recognitionTask = speechRecognizer.recognitionTask(with: recognitionRequest) { [weak self] result, error in
result!.bestTranscription.formattedString
@dbolella
dbolella / SwappingTaps.swift
Created September 30, 2019 19:38
Swapping Taps
//*********went from this*********
let asset = AVURLAsset(url: url)
guard let audioTrack = asset.tracks(withMediaType: AVMediaType.audio).first else {
print("can't get audioTrack")
return
}
playerItem = AVPlayerItem(asset: asset)
tap = MYAudioTapProcessor(audioAssetTrack: audioTrack)
tap.delegate = self
@dbolella
dbolella / ObservedString.swift
Last active October 2, 2019 17:02
ObservedObject
class CaptionCollector: ObservableObject {
@Published var caption: String = ""
}
@ObservedObject var capCollect = CaptionCollector()
//...
Text(self.capCollect.caption)
@dbolella
dbolella / TranscriptionResultsProtocol.swift
Created October 2, 2019 17:06
Collecting the Caption through Protocol
class CaptionCollector: ObservableObject {
@Published var caption: String = ""
}
@ObservedObject var capCollect = CaptionCollector()
//protocol function
func captioningUpdated(caption: String) {
self.capCollect.caption = caption
}
@dbolella
dbolella / StartRecordingTranscription.swift
Created October 9, 2019 16:59
Start Recording Function
//Thanks to https://developer.apple.com/documentation/speech/recognizing_speech_in_live_audio
func startRecording() throws {
// Cancel the previous task if it's running.
recognitionTask?.cancel()
self.recognitionTask = nil
// Configure the audio session for the app.
let audioSession = AVAudioSession.sharedInstance()
try audioSession.setCategory(.record, mode: .measurement, options: .duckOthers)
@dbolella
dbolella / TranslateKotlinController.swift
Created October 10, 2019 20:06
The Translation Controller for SwiftKotlinOnline
import Vapor
import Transform
import SwiftKotlinFramework
import Cocoa
/// Here we have a controller that helps facilitate
/// creating typical REST patterns
final class TranslateKotlinController {
/// POST /translate
func store(_ req: Request) throws -> Future<View> {
@dbolella
dbolella / input.leaf
Created October 10, 2019 20:31
Leafs for SwiftKotlinOnline
#set("title") { Translate Kotlin }
#set("body") {
<textarea id="constantsText" rows="4" cols="50">
Please put swift code here...
</textarea>
<button onclick="post()">Click me</button>
<script>
function post() {
@dbolella
dbolella / LinkPreviewFail.swift
Created October 29, 2019 18:53
Lacking implementation of LinkPreview in SwiftUI
struct ContentView: View {
var body: some View {
VStack {
URLPreview(previewURL: URL(string: "https://medium.com")!)
.aspectRatio(contentMode: .fit)
.padding()
}
}
}