Skip to content

Fix: Resolve AudioContext initialization error and sync volume control#31

Merged
alexykn merged 1 commit intomainfrom
fix/audio-context-volume-sync
May 24, 2025
Merged

Fix: Resolve AudioContext initialization error and sync volume control#31
alexykn merged 1 commit intomainfrom
fix/audio-context-volume-sync

Conversation

@alexykn
Copy link
Owner

@alexykn alexykn commented May 24, 2025

This commit addresses the "Cannot read properties of null (reading 'value')" error related to AudioContext initialization and resolves inconsistencies in volume control.

Key changes:

  1. Error Handling in useTTS.js:

    • Added defensive checks in generateSpeech and generateMultiSpeech after initAudio() to ensure audioContext and audioContext.value are valid. This prevents errors if AudioContext fails to initialize and provides clearer error feedback to you.
    • Added logging to aid in diagnosing AudioContext issues.
  2. Volume Control Synchronization:

    • Refactored useTTS.js to use the setVolumeAndApply action from ttsStore.js. This ensures that changes to the volume are reflected in both the Pinia store and the Web Audio API's gainNode.
    • The reset() function in useTTS.js now correctly uses the synchronized volume setting.
    • This fixes the issue where UI volume could be out of sync with the actual audio volume.
  3. Initial Volume in useAudioContext.js:

    • Modified initAudio() in useAudioContext.js to set the initial gain value of the gainNode based on the volume stored in ttsStore.js. This ensures volume consistency from the moment audio is initialized.

These changes improve the robustness of audio feature initialization and provide a more consistent state management for volume control.

This commit addresses the "Cannot read properties of null (reading 'value')" error related to AudioContext initialization and resolves inconsistencies in volume control.

Key changes:

1.  **Error Handling in `useTTS.js`**:
    *   Added defensive checks in `generateSpeech` and `generateMultiSpeech` after `initAudio()` to ensure `audioContext` and `audioContext.value` are valid. This prevents errors if `AudioContext` fails to initialize and provides clearer error feedback to you.
    *   Added logging to aid in diagnosing `AudioContext` issues.

2.  **Volume Control Synchronization**:
    *   Refactored `useTTS.js` to use the `setVolumeAndApply` action from `ttsStore.js`. This ensures that changes to the volume are reflected in both the Pinia store and the Web Audio API's `gainNode`.
    *   The `reset()` function in `useTTS.js` now correctly uses the synchronized volume setting.
    *   This fixes the issue where UI volume could be out of sync with the actual audio volume.

3.  **Initial Volume in `useAudioContext.js`**:
    *   Modified `initAudio()` in `useAudioContext.js` to set the initial gain value of the `gainNode` based on the volume stored in `ttsStore.js`. This ensures volume consistency from the moment audio is initialized.

These changes improve the robustness of audio feature initialization and provide a more consistent state management for volume control.
@alexykn alexykn merged commit 94596df into main May 24, 2025
1 check passed
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.

1 participant