mirror of
https://github.com/ggerganov/whisper.cpp.git
synced 2025-08-16 03:18:26 +02:00
.devops
.github
bindings
ci
cmake
examples
addon.node
bench
bench.wasm
cli
command
command.wasm
deprecation-warning
lsp
python
quantize
server
stream
stream.wasm
sycl
talk-llama
vad-speech-segments
wchess
whisper.android
whisper.android.java
whisper.nvim
whisper.objc
whisper.swiftui
whisper.cpp.swift
whisper.swiftui.demo
Models
Resources
Supporting files
UI
Utils
Recorder.swift
RiffWaveUtils.swift
WhisperCppDemoApp.swift
whisper.swiftui.xcodeproj
.gitignore
README.md
whisper.wasm
CMakeLists.txt
coi-serviceworker.js
common-ggml.cpp
common-ggml.h
common-sdl.cpp
common-sdl.h
common-whisper.cpp
common-whisper.h
common.cpp
common.h
ffmpeg-transcode.cpp
generate-karaoke.sh
grammar-parser.cpp
grammar-parser.h
helpers.js
json.hpp
livestream.sh
miniaudio.h
server.py
stb_vorbis.c
twitch.sh
yt-wsp.sh
ggml
grammars
include
models
samples
scripts
src
tests
.dockerignore
.gitignore
AUTHORS
CMakeLists.txt
LICENSE
Makefile
README.md
README_sycl.md
build-xcframework.sh
close-issue.yml
36 lines
1.0 KiB
Swift
36 lines
1.0 KiB
Swift
import Foundation
|
|
import AVFoundation
|
|
|
|
actor Recorder {
|
|
private var recorder: AVAudioRecorder?
|
|
|
|
enum RecorderError: Error {
|
|
case couldNotStartRecording
|
|
}
|
|
|
|
func startRecording(toOutputFile url: URL, delegate: AVAudioRecorderDelegate?) throws {
|
|
let recordSettings: [String : Any] = [
|
|
AVFormatIDKey: Int(kAudioFormatLinearPCM),
|
|
AVSampleRateKey: 16000.0,
|
|
AVNumberOfChannelsKey: 1,
|
|
AVEncoderAudioQualityKey: AVAudioQuality.high.rawValue
|
|
]
|
|
#if !os(macOS)
|
|
let session = AVAudioSession.sharedInstance()
|
|
try session.setCategory(.playAndRecord, mode: .default)
|
|
#endif
|
|
let recorder = try AVAudioRecorder(url: url, settings: recordSettings)
|
|
recorder.delegate = delegate
|
|
if recorder.record() == false {
|
|
print("Could not start recording")
|
|
throw RecorderError.couldNotStartRecording
|
|
}
|
|
self.recorder = recorder
|
|
}
|
|
|
|
func stopRecording() {
|
|
recorder?.stop()
|
|
recorder = nil
|
|
}
|
|
}
|