Doubao-powered voice input for Linux, Wayland and Omarchy
import AppKit
import Foundation
let directory = URL(fileURLWithPath: CommandLine.arguments[1])
try FileManager.default.createDirectory(at: directory, withIntermediateDirectories: true)
// The PNG is generated from ui/bunspeak.svg; Linux, website, and macOS share the artwork.
let source = URL(fileURLWithPath: #filePath).deletingLastPathComponent()
.appendingPathComponent("../../src/doubao_input/resources/logo.png").standardizedFileURL
let artwork = NSImage(contentsOf: source)!
for size in [16, 32, 64, 128, 256, 512, 1024] {
let bitmap = NSBitmapImageRep(bitmapDataPlanes: nil, pixelsWide: size, pixelsHigh: size, bitsPerSample: 8, samplesPerPixel: 4, hasAlpha: true, isPlanar: false, colorSpaceName: .deviceRGB, bytesPerRow: 0, bitsPerPixel: 0)!
NSGraphicsContext.saveGraphicsState()
NSGraphicsContext.current = NSGraphicsContext(bitmapImageRep: bitmap)
NSGraphicsContext.current?.imageInterpolation = .high
artwork.draw(in: NSRect(x: 0, y: 0, width: size, height: size))
NSGraphicsContext.restoreGraphicsState()
let png = bitmap.representation(using: .png, properties: [:])!
try png.write(to: directory.appendingPathComponent("render_\(size).png"))
}