Skip to content

Commit

Permalink
Change to react-native-player
Browse files Browse the repository at this point in the history
  • Loading branch information
hans00 committed Dec 24, 2023
1 parent 3ea8f51 commit cd52cbf
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 32 deletions.
5 changes: 2 additions & 3 deletions components/models/ASR.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React, { useState, useEffect, useCallback, useRef } from 'react';
import { View, Text, PermissionsAndroid, Platform, Alert } from 'react-native';
import SoundPlayer from 'react-native-sound-player';
import SelectField from '../form/SelectField';
import TextField from '../form/TextField';
import NumberField from '../form/NumberField';
Expand All @@ -10,7 +9,7 @@ import Recorder from '../../utils/recorder';
import InlineSection from '../form/InlineSection';
import Section from '../form/Section';
import { useColor } from '../../utils/style';
import { decodeBuffer, toSingleChannel, downsample } from '../../utils/audio';
import { decodeBuffer, toSingleChannel, downsample, play } from '../../utils/audio';
import { getFile } from '../../utils/fs-cache';
import * as logger from '../../utils/logger';

Expand Down Expand Up @@ -93,7 +92,7 @@ export function Interact({ settings: { model }, params, runPipe }: InteractProps

const playExample = useCallback(async () => {
if (!example) return;
SoundPlayer.playUrl(example);
play(example);
}, [example]);

return (
Expand Down
5 changes: 2 additions & 3 deletions components/models/TTS.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import React, { useState, useEffect, useCallback, useRef } from 'react';
import { Text, Platform, Alert } from 'react-native';
import SoundPlayer from 'react-native-sound-player';
import RNFS from 'react-native-fs';
import SelectField from '../form/SelectField';
import TextField from '../form/TextField';
import NumberField from '../form/NumberField';
import BooleanField from '../form/BooleanField';
import Button from '../form/Button';
import { encodeBuffer } from '../../utils/audio';
import { encodeBuffer, play } from '../../utils/audio';

export const title = 'Text To Speech';

Expand Down Expand Up @@ -75,7 +74,7 @@ export function Interact({ settings: { model }, params, runPipe }: InteractProps

const play = useCallback(() => {
if (!output) return;
SoundPlayer.playSoundFile(output.replace('.wav', ''), 'wav');
play(output);
}, [output]);

return (
Expand Down
9 changes: 9 additions & 0 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,11 @@ PODS:
- React
- RNFS (2.20.0):
- React-Core
- RNSound (0.11.2):
- React-Core
- RNSound/Core (= 0.11.2)
- RNSound/Core (0.11.2):
- React-Core
- RNSoundPlayer (0.13.2):
- React-Core
- SocketRocket (0.6.0)
Expand Down Expand Up @@ -502,6 +507,7 @@ DEPENDENCIES:
- ReactCommon/turbomodule/core (from `../node_modules/react-native/ReactCommon`)
- "RNAudioPcmStream (from `../node_modules/@fugood/react-native-audio-pcm-stream`)"
- RNFS (from `../node_modules/react-native-fs`)
- RNSound (from `../node_modules/react-native-sound`)
- RNSoundPlayer (from `../node_modules/react-native-sound-player`)
- Yoga (from `../node_modules/react-native/ReactCommon/yoga`)

Expand Down Expand Up @@ -603,6 +609,8 @@ EXTERNAL SOURCES:
:path: "../node_modules/@fugood/react-native-audio-pcm-stream"
RNFS:
:path: "../node_modules/react-native-fs"
RNSound:
:path: "../node_modules/react-native-sound"
RNSoundPlayer:
:path: "../node_modules/react-native-sound-player"
Yoga:
Expand Down Expand Up @@ -662,6 +670,7 @@ SPEC CHECKSUMS:
ReactCommon: 85c98ab0a509e70bf5ee5d9715cf68dbf495b84c
RNAudioPcmStream: d7491fdfe6bddcebd6ab325df8327014be16743f
RNFS: 4ac0f0ea233904cb798630b3c077808c06931688
RNSound: 6c156f925295bdc83e8e422e7d8b38d33bc71852
RNSoundPlayer: 369105c565b8fe6ea0a43fc882dc81eba444e842
SocketRocket: fccef3f9c5cedea1353a9ef6ada904fde10d6608
Yoga: 065f0b74dba4832d6e328238de46eb72c5de9556
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"react-native-image-picker": "^5.3.1",
"react-native-quick-base64": "^2.0.6",
"react-native-select-dropdown": "^3.3.3",
"react-native-sound-player": "^0.13.2",
"react-native-sound": "^0.11.2",
"resize-image-data": "^0.3.1",
"sha.js": "^2.4.11",
"stream-browserify": "^3.0.0",
Expand Down
21 changes: 0 additions & 21 deletions patches/react-native-sound-player+0.13.2.patch

This file was deleted.

13 changes: 13 additions & 0 deletions utils/audio.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import wav from 'node-wav';
import AV from 'av';
import 'mp3';
import Sound from 'react-native-sound';
import type { Buffer } from 'buffer';

const SCALING_FACTOR = Math.sqrt(2);
Expand All @@ -11,6 +12,18 @@ export interface AudioData {
channels: number;
}

export const play = (uri: string): Promise<void> => {
return new Promise((resolve, reject) => {
const sound = new Sound(uri, '', (err) => {
if (err) return reject(err);
sound.play(() => {
sound.release();
resolve();
});
});
});
};

export const encodeBuffer = (audio: AudioData): Buffer => {
const { data, sampleRate, channels } = audio;
const lenPerChannel = data.length / channels;
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6951,10 +6951,10 @@ react-native-select-dropdown@^3.3.3:
resolved "https://registry.npmjs.org/react-native-select-dropdown/-/react-native-select-dropdown-3.4.0.tgz"
integrity sha512-9xK1z4tYpwMxp3hsM0y1+xfqq/JoMh+l7sBsJ81b2eikFwT6ZbndFBqupQXrsQ1akce9hgC/10Nkzj0LjVjeXQ==

react-native-sound-player@^0.13.2:
version "0.13.2"
resolved "https://registry.npmjs.org/react-native-sound-player/-/react-native-sound-player-0.13.2.tgz"
integrity sha512-m457mjp496sARAED7epYzbhorfiLZ3j6HzJn7zEL9RU+ZJKcans/0gFNUEBvlh31fSDZRliQ2WwE4mJ6836bNg==
react-native-sound@^0.11.2:
version "0.11.2"
resolved "https://registry.yarnpkg.com/react-native-sound/-/react-native-sound-0.11.2.tgz#e542dc5b9e16ab4b3ac7e6eaddb1fc8d98da9038"
integrity sha512-LmGc8lgOK3qecYMVQpyHvww/C+wgT6sWeMpVbOe4NCRGC2yKd4fo4U0KBUo9PO7AqKESO3I/2GZg1/C0+bwiiA==

[email protected]:
version "0.71.8"
Expand Down

0 comments on commit cd52cbf

Please sign in to comment.