(outputPath string, segments [][]byte)
| 223 | } |
| 224 | |
| 225 | func writeSegmentsToFile(outputPath string, segments [][]byte) error { |
| 226 | if len(segments) == 0 { |
| 227 | return errors.New("录音分段为空") |
| 228 | } |
| 229 | if err := os.MkdirAll(filepath.Dir(outputPath), 0o755); err != nil { |
| 230 | return fmt.Errorf("创建输入目录失败: %w", err) |
| 231 | } |
| 232 | if err := ensureRecordingWritableFile(outputPath, recordingLocalArtifactMode); err != nil { |
| 233 | return err |
| 234 | } |
| 235 | f, err := os.OpenFile(outputPath, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0o600) |
| 236 | if err != nil { |
| 237 | return fmt.Errorf("创建输入文件失败: %w", err) |
| 238 | } |
| 239 | defer f.Close() |
| 240 | for i, segment := range segments { |
| 241 | if len(segment) == 0 { |
| 242 | continue |
| 243 | } |
| 244 | if _, err := f.Write(segment); err != nil { |
| 245 | return fmt.Errorf("写入分段 %d 失败: %w", i, err) |
| 246 | } |
| 247 | } |
| 248 | return ensureRecordingFileMode(outputPath, recordingLocalArtifactMode) |
| 249 | } |
| 250 | |
| 251 | func normalizeRecordingTargetFormat(targetFormat string) string { |
| 252 | targetFormat = strings.ToLower(strings.TrimSpace(strings.TrimPrefix(targetFormat, "."))) |
no test coverage detected