Fix: Resolve AudioContext initialization error and sync volume control#31
Merged
Fix: Resolve AudioContext initialization error and sync volume control#31
Conversation
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 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This commit addresses the "Cannot read properties of null (reading 'value')" error related to AudioContext initialization and resolves inconsistencies in volume control.
Key changes:
Error Handling in
useTTS.js:generateSpeechandgenerateMultiSpeechafterinitAudio()to ensureaudioContextandaudioContext.valueare valid. This prevents errors ifAudioContextfails to initialize and provides clearer error feedback to you.AudioContextissues.Volume Control Synchronization:
useTTS.jsto use thesetVolumeAndApplyaction fromttsStore.js. This ensures that changes to the volume are reflected in both the Pinia store and the Web Audio API'sgainNode.reset()function inuseTTS.jsnow correctly uses the synchronized volume setting.Initial Volume in
useAudioContext.js:initAudio()inuseAudioContext.jsto set the initial gain value of thegainNodebased on the volume stored inttsStore.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.