Generate SRT from audio (#341)
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
//
|
||||
// Audio.swift
|
||||
// SherpaOnnxSubtitle
|
||||
//
|
||||
// Created by knight on 2023/9/23.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct Audio: Transferable {
|
||||
let url: URL
|
||||
|
||||
static var transferRepresentation: some TransferRepresentation {
|
||||
FileRepresentation(contentType: .movie) { movie in
|
||||
SentTransferredFile(movie.url)
|
||||
} importing: { received in
|
||||
let copy = URL.documentsDirectory.appending(path: "audio.wav")
|
||||
|
||||
if FileManager.default.fileExists(atPath: copy.path()) {
|
||||
try FileManager.default.removeItem(at: copy)
|
||||
}
|
||||
|
||||
try FileManager.default.copyItem(at: received.file, to: copy)
|
||||
return Self(url: copy)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
//
|
||||
// Document.swift
|
||||
// YPlayer
|
||||
//
|
||||
// Created by knight on 2023/6/5.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
import UniformTypeIdentifiers
|
||||
|
||||
struct Document: FileDocument {
|
||||
static var readableContentTypes = [UTType.srt]
|
||||
static var writableContentTypes = [UTType.srt]
|
||||
var data: Data?
|
||||
|
||||
init(data: Data?) {
|
||||
self.data = data
|
||||
}
|
||||
|
||||
init(configuration: ReadConfiguration) throws {
|
||||
if let data = configuration.file.regularFileContents {
|
||||
self.data = data
|
||||
}
|
||||
}
|
||||
|
||||
func fileWrapper(configuration _: WriteConfiguration) throws -> FileWrapper {
|
||||
guard let data = data else {
|
||||
throw ExportError.fileNotFound
|
||||
}
|
||||
return FileWrapper(regularFileWithContents: data)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
//
|
||||
// Errors.swift
|
||||
// YPlayer
|
||||
//
|
||||
// Created by knight on 2023/8/26.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
enum ExportError: String, Error {
|
||||
case fileNotFound = "export file not found"
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
//
|
||||
// SpeechSegment.swift
|
||||
// SherpaOnnxSubtitle
|
||||
//
|
||||
// Created by knight on 2023/9/23.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
class SpeechSegment: CustomStringConvertible {
|
||||
let start: Float
|
||||
let end: Float
|
||||
let text: String
|
||||
|
||||
init(start: Float, duration: Float, text: String) {
|
||||
self.start = start
|
||||
end = start + duration
|
||||
self.text = text
|
||||
}
|
||||
|
||||
public var description: String {
|
||||
var s: String
|
||||
s = TimeInterval(start).hourMinuteSecondMS
|
||||
s += " --> "
|
||||
s += TimeInterval(end).hourMinuteSecondMS
|
||||
s += "\n"
|
||||
s += text
|
||||
|
||||
return s
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user