Skip to content

Feature/audio detection#201

Open
Lucas-Rosenzweig wants to merge 2 commits into
DasAmpharos:mainfrom
Lucas-Rosenzweig:feature/audio-detection
Open

Feature/audio detection#201
Lucas-Rosenzweig wants to merge 2 commits into
DasAmpharos:mainfrom
Lucas-Rosenzweig:feature/audio-detection

Conversation

@Lucas-Rosenzweig
Copy link
Copy Markdown

@Lucas-Rosenzweig Lucas-Rosenzweig commented Mar 15, 2026

Hello , this pr add a feature to start the time when a sound higher than "silence" is detected for exemple the "click" of the gba power button.
It add a button next to the settings one to start listening

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds an audio-trigger feature that listens to the microphone and starts the timer when a sound above a “silence” threshold is detected (e.g., a button click), with a new mic button in the timer footer UI.

Changes:

  • Introduces a useAudio hook to start/stop mic capture and detect loud transients.
  • Adds a microphone toggle button to TimerDisplay and corresponding styles.
  • Wires audio detection into App to start the phase runner when a sound is detected.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 8 comments.

File Description
src/hooks/useAudio.ts New hook implementing mic capture + threshold detection and start/stop lifecycle.
src/App.tsx Integrates useAudio to start the timer on detection and adds UI toggle handler.
src/components/TimerDisplay.tsx Adds mic button + props to reflect listening/detected state.
src/App.css Adds styling for footer control group and mic button states.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/hooks/useAudio.ts Outdated
Comment thread src/hooks/useAudio.ts Outdated
Comment thread src/hooks/useAudio.ts Outdated
Comment thread src/hooks/useAudio.ts Outdated
Comment thread src/hooks/useAudio.ts Outdated
Comment thread src/hooks/useAudio.ts Outdated
Comment on lines +1 to +13
import {useCallback, useEffect, useRef, useState} from 'react';

const THRESHOLD = 60;
const SILENCE_CENTER = 128;

interface UseAudioOptions {
onDetect?: () => void;
threshold?: number;
}

export const useAudio = (options?: UseAudioOptions) => {
const [isDetected, setIsDetected] = useState(false);
const [isListening, setIsListening] = useState(false);
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Is this important for you ? @DasAmpharos
If so, I'll change it.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I would like to keep the code style consistent. Please update when you get a chance

Comment thread src/App.tsx Outdated
Comment thread src/components/TimerDisplay.tsx
@DasAmpharos
Copy link
Copy Markdown
Owner

Thanks @Lucas-Rosenzweig for the pull request! Please see the review comments made by copilot and make changes accordingly

@Lucas-Rosenzweig
Copy link
Copy Markdown
Author

Lucas-Rosenzweig commented Mar 17, 2026

Hello , i miss clicked when i selected the repo to put the pr on x) so it was a first draft so i didn't even re read my code.

I'm gonna check that and make the change

@Lucas-Rosenzweig Lucas-Rosenzweig force-pushed the feature/audio-detection branch from f0cf0f5 to 311b1d3 Compare March 18, 2026 19:44
Copy link
Copy Markdown
Owner

@DasAmpharos DasAmpharos left a comment

Choose a reason for hiding this comment

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

Please fix the merge conflicts as well

Comment thread src/hooks/useAudio.ts Outdated
setIsListening(false);
}, []);

const startListening = async () => {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Please wrap this in useCallback

Comment thread src/hooks/useAudio.ts Outdated
onDetectRef.current = options?.onDetect;
}, [options?.onDetect]);

function calculateMaxDeviation(dataArray: Uint8Array) {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Please move this out of the hook body. Since this is a pure function with no dependency on hook state, refs or props, defining it in the body will result in this function being re-created every render.

Comment thread src/hooks/useAudio.ts
@@ -0,0 +1,126 @@
import {useCallback, useEffect, useRef, useState} from 'react';

const THRESHOLD = 60;
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Please make THRESHOLD configurable via settings rather than hard-coding the value so users can tune the detection sensitivity

Adds a microphone button next to the settings gear in the timer footer.
When active, the app listens for audio above a silence threshold and
automatically starts the timer on the first detected sound (e.g. the
click of a GBA power button). Listening stops automatically once the
timer starts or when the user manually deactivates it.

Co-authored-by: Lucas-Rosenzweig <38187137+Lucas-Rosenzweig@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@DasAmpharos DasAmpharos force-pushed the feature/audio-detection branch from 311b1d3 to c354035 Compare March 24, 2026 02:31
@github-actions
Copy link
Copy Markdown

🚀 Preview deployment

https://dasampharos.github.io/EonTimer-dev/pr-201/

Updated on every push to this PR.

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.

3 participants