Skip to content

Commit 521a5cd

Browse files
committed
docs: update README.md
1 parent 7a5da10 commit 521a5cd

File tree

4 files changed

+79
-35
lines changed

4 files changed

+79
-35
lines changed

README.md

Lines changed: 79 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ cd ios && pod install
1616
With this library, unleash creativity by generating captivating audio waveforms from your audio tracks, providing an engaging visual representation of sound.
1717

1818
<p float="left">
19-
<img src="images/android.png" width="200" alt="android"/>
20-
<img src="images/ios.png" width="200" alt="ios"/>
19+
<img src="images/image.png" width="200" alt="android"/>
2120
</p>
2221

2322
## Features ✨
@@ -34,74 +33,119 @@ With this library, unleash creativity by generating captivating audio waveforms
3433
## Usage 🎶
3534

3635
```js
37-
import { analyzeAudio, scale, sample } from 'react-native-audio-analyzer';
36+
import React, { useCallback, useState } from 'react';
37+
38+
import {
39+
ActivityIndicator,
40+
Alert,
41+
Button,
42+
ScrollView,
43+
StyleSheet,
44+
Text,
45+
View,
46+
} from 'react-native';
47+
import {
48+
analyzeAudio,
49+
scale,
50+
sample,
51+
robustScale,
52+
trimmedScale,
53+
} from 'react-native-audio-analyzer';
54+
import type { AmplitudeData } from 'react-native-audio-analyzer';
3855
import ReactNativeBlobUtil from 'react-native-blob-util';
3956

4057
export default function App() {
41-
const [result, setResult] = useState([]);
58+
const [result, setResult] = useState<AmplitudeData[]>([]);
59+
const [isLoading, setIsLoading] = useState(false);
4260

4361
const start = useCallback(async () => {
4462
try {
63+
setIsLoading(true);
4564
const response = await ReactNativeBlobUtil.config({
4665
fileCache: true,
4766
}).fetch(
4867
'GET',
49-
'https://file-examples.com/storage/fe61380d0265a2c7a970ef9/2017/11/file_example_WAV_10MG.wav',
68+
'https://github.com/rafaelreis-hotmart/Audio-Sample-files/raw/master/sample.mp3',
5069
{}
5170
);
5271
const path = response.path();
53-
const data = await analyzeAudio(path);
72+
const data = await analyzeAudio(path, 2);
5473
setResult(data);
5574
} catch (error) {
56-
console.log(error);
75+
Alert.alert('Error', String(error));
76+
} finally {
77+
setIsLoading(false);
5778
}
5879
}, []);
5980

81+
const amplitudes = result.map((_) => _.amplitude);
82+
83+
const results = [
84+
{
85+
title: 'Trimmed scale:',
86+
data: trimmedScale(amplitudes).map((value, index) => (
87+
<View key={index} style={[styles.item, { height: value * 100 }]} />
88+
)),
89+
},
90+
{
91+
title: 'Robust scale:',
92+
data: robustScale(amplitudes).map((value, index) => (
93+
<View key={index} style={[styles.item, { height: value * 100 }]} />
94+
)),
95+
},
96+
{
97+
title: 'Scale + sample:',
98+
data: scale(sample(amplitudes, 35)).map((value, index) => (
99+
<View key={index} style={[styles.item, { height: value * 100 }]} />
100+
)),
101+
},
102+
{
103+
title: 'Scale:',
104+
data: scale(amplitudes).map((value, index) => (
105+
<View key={index} style={[styles.item, { height: value * 100 }]} />
106+
)),
107+
},
108+
];
109+
60110
return (
61111
<View style={styles.container}>
62112
<Button title="Start" onPress={start} />
63-
<ScrollView horizontal style={styles.scroll}>
64-
<View style={styles.row}>
65-
{result.length > 0 &&
66-
scale(result.map((_) => _.amplitude)).map((value, index) => (
67-
<View
68-
key={index}
69-
style={[styles.item, { height: value * 100 }]}
70-
/>
71-
))}
72-
</View>
73-
</ScrollView>
74-
<ScrollView horizontal style={styles.scroll}>
75-
<View style={styles.row}>
76-
{result.length > 0 &&
77-
scale(
78-
sample(
79-
result.map((_) => _.amplitude),
80-
20
81-
)
82-
).map((value, index) => (
83-
<View
84-
key={index}
85-
style={[styles.item, { height: value * 100 }]}
86-
/>
87-
))}
113+
{isLoading ? (
114+
<ActivityIndicator style={styles.loader} size="large" />
115+
) : (
116+
<View>
117+
{results.map((_, index) => (
118+
<View style={styles.example} key={index}>
119+
<Text style={styles.title}>{_.title}</Text>
120+
<ScrollView horizontal style={styles.scroll}>
121+
<View style={styles.row}>{_.data}</View>
122+
</ScrollView>
123+
</View>
124+
))}
88125
</View>
89-
</ScrollView>
126+
)}
90127
</View>
91128
);
92129
}
93130

94131
const styles = StyleSheet.create({
95132
container: {
96133
flex: 1,
97-
alignItems: 'center',
98134
justifyContent: 'center',
99135
backgroundColor: '#ffffff',
100136
},
137+
loader: {
138+
padding: 30,
139+
},
101140
row: {
102141
flexDirection: 'row',
103142
alignItems: 'center',
104-
justifyContent: 'center',
143+
},
144+
title: {
145+
marginBottom: 5,
146+
},
147+
example: {
148+
padding: 10,
105149
},
106150
scroll: {
107151
maxHeight: 200,

images/android.png

-44.4 KB
Binary file not shown.

images/image.png

65.3 KB
Loading

images/ios.png

-72.1 KB
Binary file not shown.

0 commit comments

Comments
 (0)