Skip to content

Commit 2c84e8d

Browse files
authored
fix: audio distortion on audio rate change (#3056)
1 parent 8b2d7e3 commit 2c84e8d

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

package/src/components/Attachment/AudioAttachment.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,9 @@ export const AudioAttachment = (props: AudioAttachmentProps) => {
184184
soundRef.current = await NativeHandlers.Sound.initializeSound(
185185
{ uri: item.file.uri },
186186
{
187+
pitchCorrectionQuality: 'high',
187188
progressUpdateIntervalMillis: 100,
189+
shouldCorrectPitch: true,
188190
},
189191
onPlaybackStatusUpdate,
190192
);

package/src/hooks/useAudioPlayer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export const useAudioPlayer = (props: UseSoundPlayerProps) => {
7171
return;
7272
}
7373
if (soundRef.current?.setRateAsync) {
74-
await soundRef.current.setRateAsync(speed);
74+
await soundRef.current.setRateAsync(speed, true, 'high');
7575
}
7676
},
7777
[isExpoCLI, soundRef],

package/src/native.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,12 @@ export type PlaybackStatus = {
107107
shouldPlay: boolean;
108108
};
109109

110+
export type PitchCorrectionQuality = 'low' | 'medium' | 'high';
111+
110112
export type AVPlaybackStatusToSet = {
111113
isLooping: boolean;
112114
isMuted: boolean;
115+
pitchCorrectionQuality: PitchCorrectionQuality;
113116
positionMillis: number;
114117
progressUpdateIntervalMillis: number;
115118
rate: number;
@@ -152,7 +155,11 @@ export type SoundReturnType = {
152155
seek?: (progress: number, tolerance?: number) => void;
153156
setPositionAsync?: (millis: number) => void;
154157
setProgressUpdateIntervalAsync?: (progressUpdateIntervalMillis: number) => void;
155-
setRateAsync?: (rate: number) => void;
158+
setRateAsync?: (
159+
rate: number,
160+
shouldCorrectPitch: boolean,
161+
pitchCorrectionQuality?: PitchCorrectionQuality,
162+
) => void;
156163
soundRef?: React.RefObject<SoundReturnType>;
157164
stopAsync?: () => void;
158165
style?: StyleProp<ViewStyle>;

0 commit comments

Comments
 (0)