未验证 提交 35e1252f 编写于 作者: Y YixinKristy 提交者: GitHub

upgrade reademe-audio part (#761)

* Update README-en.md

* Update README.md

* Update README.md

* Update README.md

* Update UserGuide-en.md
上级 9bfdb9bb
...@@ -231,7 +231,7 @@ app.run(logdir="./log") ...@@ -231,7 +231,7 @@ app.run(logdir="./log")
实时展示训练过程中的图像数据,用于观察不同训练阶段的图像变化,进而深入了解训练过程及效果。 实时展示训练过程中的图像数据,用于观察不同训练阶段的图像变化,进而深入了解训练过程及效果。
<p align="center"> <p align="center">
<img src="https://visualdl.bj.bcebos.com/images/image-eye.gif" width="60%"/> <img src="https://user-images.githubusercontent.com/48054808/90356439-24715980-e082-11ea-8896-01c27fc2fc9b.gif" width="85%"/>
</p> </p>
### Audio ### Audio
......
...@@ -231,7 +231,7 @@ app.run(logdir="./log") ...@@ -231,7 +231,7 @@ app.run(logdir="./log")
实时展示训练过程中的图像数据,用于观察不同训练阶段的图像变化,进而深入了解训练过程及效果。 实时展示训练过程中的图像数据,用于观察不同训练阶段的图像变化,进而深入了解训练过程及效果。
<p align="center"> <p align="center">
<img src="https://visualdl.bj.bcebos.com/images/image-eye.gif" width="60%"/> <img src="https://user-images.githubusercontent.com/48054808/90356439-24715980-e082-11ea-8896-01c27fc2fc9b.gif" width="85%"/>
</p> </p>
### Audio ### Audio
......
...@@ -289,38 +289,19 @@ add_audio(tag, audio_array, step, sample_rate) ...@@ -289,38 +289,19 @@ add_audio(tag, audio_array, step, sample_rate)
### Demo ### Demo
下面展示了使用 Audio 组件记录数据的示例,代码文件请见[Audio组件](https://github.com/PaddlePaddle/VisualDL/blob/develop/demo/components/audio_test.py)
```python ```python
from visualdl import LogWriter from visualdl import LogWriter
import numpy as np from scipy.io import wavfile
import wave
def read_audio_data(audio_path):
"""
Get audio data.
"""
CHUNK = 4096
f = wave.open(audio_path, "rb")
wavdata = []
chunk = f.readframes(CHUNK)
while chunk:
data = np.frombuffer(chunk, dtype='uint8')
wavdata.extend(data)
chunk = f.readframes(CHUNK)
# 8k sample rate, 16bit frame, 1 channel
shape = [8000, 2, 1]
return shape, wavdata
if __name__ == '__main__': if __name__ == '__main__':
with LogWriter(logdir="./log") as writer: with LogWriter(logdir="./log/audio_test/train") as writer:
audio_shape, audio_data = read_audio_data("./testing.wav") sample_rate, audio_data = wavfile.read('./test.wav')
audio_data = np.array(audio_data)
writer.add_audio(tag="audio_tag", writer.add_audio(tag="audio_tag",
audio_array=audio_data, audio_array=audio_data,
step=0, step=0,
sample_rate=8000) sample_rate=sample_rate)
``` ```
运行上述程序后,在命令行执行 运行上述程序后,在命令行执行
......
...@@ -294,35 +294,16 @@ The following shows an example of using Audio to record data, and the script can ...@@ -294,35 +294,16 @@ The following shows an example of using Audio to record data, and the script can
```python ```python
from visualdl import LogWriter from visualdl import LogWriter
import numpy as np from scipy.io import wavfile
import wave
def read_audio_data(audio_path):
"""
Get audio data.
"""
CHUNK = 4096
f = wave.open(audio_path, "rb")
wavdata = []
chunk = f.readframes(CHUNK)
while chunk:
data = np.frombuffer(chunk, dtype='uint8')
wavdata.extend(data)
chunk = f.readframes(CHUNK)
# 8k sample rate, 16bit frame, 1 channel
shape = [8000, 2, 1]
return shape, wavdata
if __name__ == '__main__': if __name__ == '__main__':
with LogWriter(logdir="./log") as writer: with LogWriter(logdir="./log/audio_test/train") as writer:
audio_shape, audio_data = read_audio_data("./testing.wav") sample_rate, audio_data = wavfile.read('./test.wav')
audio_data = np.array(audio_data)
writer.add_audio(tag="audio_tag", writer.add_audio(tag="audio_tag",
audio_array=audio_data, audio_array=audio_data,
step=0, step=0,
sample_rate=8000) sample_rate=sample_rate)
``` ```
After running the above program, developers can launch the panel by: After running the above program, developers can launch the panel by:
```shell ```shell
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册