-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add audio input and audio output widgets (#47) #48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
claude
wants to merge
8
commits into
main
Choose a base branch
from
claude/add-audio-in-out-widgets
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
8ec8a0e
feat: add audio input and audio output widgets (#47)
github-actions[bot] b6ffc80
fix: sort AudioInput/OutputWidget exports after Arm in index.ts
github-actions[bot] c1a58eb
add audio i/o to widgets
DTCurrie 9d47e23
Merge branch 'claude/add-audio-in-out-widgets' of https://github.com/…
DTCurrie 89f8bb0
lint
DTCurrie b25441d
pr comments
DTCurrie 0f5d864
cleanup
DTCurrie 838215d
Merge branch 'main' of https://github.com/viamrobotics/test-widgets i…
DTCurrie File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@viamrobotics/test-widgets': minor | ||
| --- | ||
|
|
||
| Add `AudioInputWidget` and `AudioOutputWidget` components for audio in/out resources |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
126 changes: 126 additions & 0 deletions
126
src/lib/components/widgets/audio-input/__tests__/audio-capture.svelte.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,126 @@ | ||
| import { flushSync } from 'svelte' | ||
| import { describe, expect, it, vi } from 'vitest' | ||
|
|
||
| import { createAudioCapturer } from '../create-audio-capturer.svelte.ts' | ||
|
|
||
| type MockAudioInClient = { | ||
| callOptions: Record<string, unknown> | ||
| getAudio: ReturnType<typeof vi.fn> | ||
| } | ||
|
|
||
| const makeClient = (mockGetAudio: ReturnType<typeof vi.fn>): { current: MockAudioInClient } => ({ | ||
| current: { | ||
| callOptions: {}, | ||
| getAudio: mockGetAudio, | ||
| }, | ||
| }) | ||
|
|
||
| async function* makeChunkStream(chunks: Uint8Array[]) { | ||
| for (const chunk of chunks) { | ||
| yield { audioData: chunk } | ||
| } | ||
| } | ||
|
|
||
| async function* makeErrorStream(message: string) { | ||
| yield { audioData: new Uint8Array([1]) } | ||
| throw new Error(message) | ||
| } | ||
|
|
||
| async function* makeAbortableStream(signal: AbortSignal) { | ||
| yield { audioData: new Uint8Array([1, 2, 3]) } | ||
| await new Promise<never>((_, reject) => { | ||
| signal.addEventListener('abort', () => reject(signal.reason)) | ||
| }) | ||
| } | ||
|
|
||
| describe('createAudioCapture', () => { | ||
| it('successful capture sets status to done and provides downloadUrl with correct totalBytes', async () => { | ||
| const chunk1 = new Uint8Array([1, 2, 3]) | ||
| const chunk2 = new Uint8Array([4, 5]) | ||
| const mockGetAudio = vi.fn().mockReturnValue(makeChunkStream([chunk1, chunk2])) | ||
|
|
||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| const client = makeClient(mockGetAudio) as any | ||
|
|
||
| let capture: ReturnType<typeof createAudioCapturer> | undefined | ||
|
|
||
| const cleanup = $effect.root(() => { | ||
| capture = createAudioCapturer(client) | ||
| }) | ||
|
|
||
| try { | ||
| await capture!.start('wav', 3) | ||
| flushSync() | ||
|
|
||
| expect(capture!.status).toBe('done') | ||
| expect(capture!.downloadUrl).toBeDefined() | ||
| expect(capture!.totalBytes).toBe(chunk1.byteLength + chunk2.byteLength) | ||
| expect(capture!.error).toBeNull() | ||
| } finally { | ||
| cleanup() | ||
| } | ||
| }) | ||
|
|
||
| it('error in stream sets status to error with the error message', async () => { | ||
| const mockGetAudio = vi.fn().mockReturnValue(makeErrorStream('stream failed')) | ||
|
|
||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| const client = makeClient(mockGetAudio) as any | ||
|
|
||
| let capture: ReturnType<typeof createAudioCapturer> | undefined | ||
|
|
||
| const cleanup = $effect.root(() => { | ||
| capture = createAudioCapturer(client) | ||
| }) | ||
|
|
||
| try { | ||
| await capture!.start('wav', 3) | ||
| flushSync() | ||
|
|
||
| expect(capture!.status).toBe('error') | ||
| expect(capture!.error?.message).toBe('stream failed') | ||
| } finally { | ||
| cleanup() | ||
| } | ||
| }) | ||
|
|
||
| it('stop aborts the stream and sets status to done without an error', async () => { | ||
| const mockGetAudio = vi | ||
| .fn() | ||
| .mockImplementation( | ||
| ( | ||
| _codec: string, | ||
| _duration: number, | ||
| _offset: bigint, | ||
| _extra: unknown, | ||
| callOptions: { signal: AbortSignal } | ||
| ) => makeAbortableStream(callOptions.signal) | ||
| ) | ||
|
|
||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| const client = makeClient(mockGetAudio) as any | ||
|
|
||
| let capture: ReturnType<typeof createAudioCapturer> | undefined | ||
|
|
||
| const cleanup = $effect.root(() => { | ||
| capture = createAudioCapturer(client) | ||
| }) | ||
|
|
||
| try { | ||
| const startPromise = capture!.start('wav', 0) | ||
|
|
||
| // Let the stream start and yield the first chunk | ||
| await new Promise((resolve) => setTimeout(resolve, 0)) | ||
|
|
||
| capture!.stop() | ||
|
|
||
| await startPromise | ||
| flushSync() | ||
|
|
||
| expect(capture!.status).toBe('done') | ||
| expect(capture!.error).toBeNull() | ||
| } finally { | ||
| cleanup() | ||
| } | ||
| }) | ||
| }) |
36 changes: 36 additions & 0 deletions
36
src/lib/components/widgets/audio-input/__tests__/properties.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| import type { ComponentProps } from 'svelte' | ||
|
|
||
| import { render, screen } from '@testing-library/svelte' | ||
| import { describe, expect, it } from 'vitest' | ||
|
|
||
| import Subject from '../properties.svelte' | ||
|
|
||
| const renderSubject = (props: Partial<ComponentProps<typeof Subject>> = {}) => | ||
| render(Subject, { | ||
| supportedCodecs: [], | ||
| sampleRateHz: 0, | ||
| numChannels: 0, | ||
| ...props, | ||
| }) | ||
|
|
||
| describe('AudioInput Properties', () => { | ||
| it('displays supported codecs', () => { | ||
| renderSubject({ supportedCodecs: ['mp3', 'pcm16'] }) | ||
| expect(screen.getByText('mp3, pcm16')).toBeInTheDocument() | ||
| }) | ||
|
|
||
| it('displays None when no codecs are supported', () => { | ||
| renderSubject({ supportedCodecs: [] }) | ||
| expect(screen.getByText('None')).toBeInTheDocument() | ||
| }) | ||
|
|
||
| it('displays sample rate', () => { | ||
| renderSubject({ sampleRateHz: 48000 }) | ||
| expect(screen.getByText('48000 Hz')).toBeInTheDocument() | ||
| }) | ||
|
|
||
| it('displays number of channels', () => { | ||
| renderSubject({ numChannels: 2 }) | ||
| expect(screen.getByText('2')).toBeInTheDocument() | ||
| }) | ||
| }) | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.