Skip to content

feat: add FFmpeg local recording and playback helpers - #685

Merged
jbeckwith-oai merged 10 commits into
mainfrom
codex/local-audio
Sep 8, 2026
Merged

feat: add FFmpeg local recording and playback helpers#685
jbeckwith-oai merged 10 commits into
mainfrom
codex/local-audio

Conversation

@jbeckwith-oai

@jbeckwith-oai jbeckwith-oai commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Summary

Add opt-in FFmpeg/FFplay helpers for recording a finite microphone clip and playing generated speech. A recording returns a finalized mono 24 kHz PCM16 WAV as an OpenAI::FilePart, ready for the existing transcription API. Playback consumes caller-provided audio streams without closing them.

  • Add OpenAI::LocalAudio.record(duration:, device: nil, timeout: nil) and .play(source, format: :auto, timeout: nil) with subprocess cleanup, optional deadlines and typed errors.
  • Use separately installed FFmpeg/FFplay, with argument arrays, a restricted environment and no shell or API credentials passed to media processes. No new gem dependencies.
  • Include a short record/transcribe/play example using the default microphone and model constants, plus public setup and device-selection instructions. Windows requires an explicit DirectShow microphone name.
  • Add an opt-in live API runner using synthetic input and FFplay's dummy output driver.

Existing Realtime API helpers and examples are unchanged. This PR adds no native audio library, companion gem, continuous device API, managed conversation session or playback-clock abstraction.

Validation

  • Focused recording/playback tests: 12 tests / 43 assertions (including real FFplay with dummy output) on Ruby 3.3 and 4.0.
  • Actual example passed live API E2E with gpt-transcribe and gpt-4o-mini-tts / marin through real FFmpeg/FFplay and synthetic media.
  • RuboCop, Sorbet examples, RBS validation and example inventory pass.

Physical microphone permissions, speaker output and platform/device compatibility were not validated by the synthetic E2E test.

@jbeckwith-oai
jbeckwith-oai requested a review from a team as a code owner September 8, 2026 16:20
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 8, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-08T20:09:30.087298Z e9ae562 New commits
🔒 Security Review Completed 2026-09-08T20:10:14.257728Z e9ae562 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@openai-sdks

openai-sdks Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

OkTest Summary

236/236 SDK tests passed in 7.975s for Ruby SDK PR #685.

Test results — 42 files
Test Result Time
tests/chat-completions-complex-body.test.ts ✅ Passed 185ms
tests/chat-completions-create.test.ts ✅ Passed 140ms
tests/chat-completions-stream.test.ts ✅ Passed 115ms
tests/files-content-binary.test.ts ✅ Passed 190ms
tests/files-create-multipart.test.ts ✅ Passed 131ms
tests/files-list-pagination.test.ts ✅ Passed 131ms
tests/initialize-config.test.ts ✅ Passed 76ms
tests/instance-isolation.test.ts ✅ Passed 128ms
tests/models-list.test.ts ✅ Passed 128ms
tests/responses-background-lifecycle.test.ts ✅ Passed 92ms
tests/responses-body-method-errors.test.ts ✅ Passed 427ms
tests/responses-cancel-timeout.test.ts ✅ Passed 254ms
tests/responses-cancel.test.ts ✅ Passed 205ms
tests/responses-compact-retries.test.ts ✅ Passed 128ms
tests/responses-compact.test.ts ✅ Passed 232ms
tests/responses-create-advanced-stream.test.ts ✅ Passed 147ms
tests/responses-create-advanced.test.ts ✅ Passed 179ms
tests/responses-create-disconnect.test.ts ✅ Passed 130ms
tests/responses-create-errors.test.ts ✅ Passed 268ms
tests/responses-create-malformed-api-responses.test.ts ✅ Passed 114ms
tests/responses-create-retries.test.ts ✅ Passed 130ms
tests/responses-create-stream-failures.test.ts ✅ Passed 103ms
tests/responses-create-stream-timeout.test.ts ✅ Passed 197ms
tests/responses-create-stream-wire.test.ts ✅ Passed 1.6s
tests/responses-create-stream.test.ts ✅ Passed 145ms
tests/responses-create-terminal-states.test.ts ✅ Passed 300ms
tests/responses-create-timeout.test.ts ✅ Passed 219ms
tests/responses-create.test.ts ✅ Passed 194ms
tests/responses-delete.test.ts ✅ Passed 102ms
tests/responses-input-items-errors.test.ts ✅ Passed 138ms
tests/responses-input-items-list.test.ts ✅ Passed 133ms
tests/responses-input-items-options.test.ts ✅ Passed 105ms
tests/responses-input-tokens-count-timeout.test.ts ✅ Passed 251ms
tests/responses-input-tokens-count.test.ts ✅ Passed 119ms
tests/responses-malformed-inputs.test.ts ✅ Passed 1.75s
tests/responses-not-found-errors.test.ts ✅ Passed 429ms
tests/responses-parse.test.ts ✅ Passed 182ms
tests/responses-retrieve-retries.test.ts ✅ Passed 186ms
tests/responses-retrieve.test.ts ✅ Passed 300ms
tests/responses-stored-method-errors.test.ts ✅ Passed 808ms
tests/retry-behavior.test.ts ✅ Passed 3.24s
tests/sdk-error-shape.test.ts ✅ Passed 334ms

View OkTest run #34272844934

SDK merge (47b9d955c532) · head (e9ae562e5ff6) · base (0e4c9062dbee) · OkTest (08ec4299e769)

@github-actions

github-actions Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Castiron custom code

✅ No new custom-code files detected.

50 mixed files remain; 0 existing customizations changed.

Compared 0e4c9062dbeee9ae562e5ff6. Generated baselines verified.

50 existing customizations unchanged
  • lib/openai.rb
  • lib/openai/client.rb
  • lib/openai/models/audio/transcription_create_response.rb
  • lib/openai/models/chat/chat_completion_message.rb
  • lib/openai/models/chat/chat_completion_message_function_tool_call.rb
  • lib/openai/models/chat/completion_create_params.rb
  • lib/openai/models/response_format_json_schema.rb
  • lib/openai/models/responses/function_tool.rb
  • lib/openai/models/responses/response.rb
  • lib/openai/models/responses/response_create_params.rb
  • lib/openai/models/responses/response_format_text_config.rb
  • lib/openai/models/responses/response_format_text_json_schema_config.rb
  • lib/openai/models/responses/response_function_tool_call.rb
  • lib/openai/models/responses/response_function_web_search.rb
  • lib/openai/models/responses/response_output_text.rb
  • lib/openai/models/responses/tool.rb
  • lib/openai/resources/beta/threads.rb
  • lib/openai/resources/chat/completions.rb
  • lib/openai/resources/containers/files.rb
  • lib/openai/resources/files.rb
  • lib/openai/resources/responses.rb
  • lib/openai/resources/vector_stores/file_batches.rb
  • lib/openai/resources/vector_stores/files.rb
  • lib/openai/resources/webhooks.rb
  • rbi/openai/client.rbi
  • rbi/openai/models/chat/chat_completion_message.rbi
  • rbi/openai/models/chat/chat_completion_message_function_tool_call.rbi
  • rbi/openai/models/chat/completion_create_params.rbi
  • rbi/openai/models/response_format_json_schema.rbi
  • rbi/openai/models/responses/response.rbi
  • rbi/openai/models/responses/response_create_params.rbi
  • rbi/openai/models/responses/response_function_tool_call.rbi
  • rbi/openai/models/responses/response_function_web_search.rbi
  • rbi/openai/models/responses/response_output_text.rbi
  • rbi/openai/resources/chat/completions.rbi
  • rbi/openai/resources/files.rbi
  • rbi/openai/resources/responses.rbi
  • rbi/openai/resources/vector_stores/file_batches.rbi
  • rbi/openai/resources/vector_stores/files.rbi
  • scripts/castiron/README.md

10 more in the full report.

A changed generated baseline means this report cannot reliably identify which handwritten lines changed.

Inspect the custom-code diff

Download the exact patch produced by this run (requires repository access):

gh run download 34272889817 --repo openai/openai-ruby \
  --name castiron-custom-code-34272889817-1 --dir /tmp/castiron-custom-code-34272889817-1
git apply --stat /tmp/castiron-custom-code-34272889817-1/custom-code.patch
cat /tmp/castiron-custom-code-34272889817-1/custom-code.patch

Or reproduce it from an SDK checkout containing the vendored reporter:

git fetch --no-tags origin 0e4c9062dbeea705f42495cfa25d9fea2e919874 e9ae562e5ff6e45cef98fb043feef4c9e81e9704
python3 scripts/castiron/custom_code_report.py report \
  --base 0e4c9062dbeea705f42495cfa25d9fea2e919874 \
  --head e9ae562e5ff6e45cef98fb043feef4c9e81e9704 --fetch --require-head-hash --public \
  --out /tmp/castiron-custom-code-e9ae562e5ff6
cat /tmp/castiron-custom-code-e9ae562e5ff6/custom-code.patch

This is the current full custom patch for mixed files, not an attribution of only the handwritten lines changed by this PR.

Full report and patch

Comment thread packages/openai-audio/test/integration_test.rb Fixed
Comment thread packages/openai-audio/test/integration_test.rb Fixed
Comment thread packages/openai-audio/test/integration_test.rb Fixed

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2dfeb4d078

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread lib/openai/helpers/realtime_audio/events.rb Outdated
Comment thread lib/openai/helpers/realtime_audio/session.rb Outdated
Comment thread lib/openai/helpers/local_audio/worker.rb Outdated

@markstuart-oai markstuart-oai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed all 44 changed files against merge base 21b8a70d48e2623e32aa01f95503adcf3fa2ba75, with actual main/base c368a06db374892273812f64c823f8d7b21871a2. Included the documentation-only update from 2dfeb4d0 to current head 69f432e9.

One additional P2 finding below: a natural-drain/interruption race can retire an item before its terminal notification and fail the session. The separate device/process and conversation layers are appropriate; no file crosses 1,000 lines. The remaining structural problem here is duplicated terminal ownership between the output ledger, session ledger and notification queue. Give that transition one owner rather than adding another late-event special case.

Fresh validation: 249 Ruby tests / 1,378 assertions passed on Ruby 4.0.6, plus three synthetic startup/teardown probes (8 assertions), C++ ring/clock checks, example Sorbet checks, lazy-loading and main-gem file-inclusion checks. A separate deterministic probe using the real AudioOutput with simulated playback reproduces the inline race. The Ruby subprocess fixtures needed this environment's Ruby launcher; no source was changed. The broader initial run had local subprocess-launcher, Sorbet PATH and proxy-test errors; the corrected passing run excludes the unchanged network-invariants file.

Ruby 3.3/3.4, native worker integration/builds (development headers unavailable), physical devices and live API were not exercised. Author-reported platform/live/type/package results remain author evidence. No devices, recordings or live API were accessed.

Comment thread lib/openai/helpers/realtime_audio/events.rb Outdated
@jbeckwith-oai jbeckwith-oai changed the title feat: add local audio devices and managed Realtime sessions feat: add FFmpeg local recording and playback helpers Sep 8, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6cace08938

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread lib/openai/helpers/local_audio/process.rb

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8944082aef

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread rbi/openai/helpers/local_audio/interface.rbi

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: fd074f1fa2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread lib/openai/helpers/local_audio.rb Outdated
Comment thread lib/openai/helpers/local_audio.rb Outdated
Comment thread lib/openai/helpers/local_audio.rb Outdated

@markstuart-oai markstuart-oai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Follow-up review of the narrowed finite FFmpeg/FFplay scope at fd074f1f, against main/base/merge base 0e4c9062. Read all 13 changed files and relevant process, IO, FilePart, type and example contracts. The managed-session/native layer is removed and existing Realtime code is unchanged; my previous terminal-ownership finding no longer applies.

Two P2 issues remain, independently reproduced below and corroborating the existing bot findings: child exit does not wake playback waiting on its source, and a boolean diagnostics check retains unbounded stderr on disk. The scope reduction substantially simplifies ownership; keeping process status and a bounded diagnostics signal with the existing process owner would further simplify these paths. No file crosses 1,000 lines; new production files are 161, 136 and 27 lines.

Fresh checks on Ruby 4.0.6: focused suite 13 tests / 47 assertions passed (including real FFplay dummy output and simulated unsupported TERM); four adversarial probes / 15 assertions characterized the two defects and verified cancellation cleanup, WAV metadata and argument boundaries. Actual FFmpeg synthetic 50 ms capture produced the expected mono 24 kHz PCM16 WAV and played through FFplay's dummy driver. Example Sorbet, RBS syntax, lazy loading, package inclusion and diff checks passed. GitHub currently reports 18 successful and two skipped checks; those are CI evidence, not local executions.

Ruby 3.3/3.4 and native Windows/macOS behavior were not run locally. No physical devices, private audio or live API were used; author-reported live E2E remains separate evidence.

Comment thread lib/openai/helpers/local_audio.rb Outdated
Comment thread lib/openai/helpers/local_audio.rb Outdated

@markstuart-oai markstuart-oai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Follow-up review at e9ae562e, against main/base/merge base 0e4c9062. Revalidated all 13 changed files, the delta from fd074f1f, and the author responses to my two P2 findings. Both are fixed: playback observes child exit while its source remains open, and stderr is drained into a bounded boolean signal without diagnostic files or another thread. Non-nil timeout validation also correctly rejects false.

The process owner now contains the diagnostic lifecycle, which removes the unnecessary tempfile lifecycle. Recording still drains child stdout completely. Existing Realtime APIs are unchanged, and the removed managed/native layer remains out of scope. No remaining substantive correctness or structural findings; no file crosses 1,000 lines (new production files: 157, 158 and 27 lines).

Fresh Ruby 4.0.6 validation: 16 tests / 56 assertions passed, including real FFplay dummy output and simulated unsupported TERM; six independent probes / 15 assertions passed for noisy exit with an open source, failed startup, cancellation, descriptor/reaping cleanup, complete recording output, no diagnostic files and timeout validation. Actual FFmpeg synthetic capture/FFplay dummy playback, example Sorbet, RBS syntax, lazy loading, package inclusion and diff checks also passed. GitHub reports 18 successful checks and two skips.

Ruby 3.3/3.4 and native Windows/macOS behavior were not exercised locally. No physical devices, private recordings or live API were used; author-reported live E2E remains separate evidence.

@jbeckwith-oai
jbeckwith-oai added this pull request to the merge queue Sep 8, 2026
Merged via the queue into main with commit 4d05097 Sep 8, 2026
20 checks passed
@jbeckwith-oai
jbeckwith-oai deleted the codex/local-audio branch September 8, 2026 21:26
@openai-sdks openai-sdks Bot mentioned this pull request Sep 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants