Skip to content

Commit

Permalink
Add audio integration demo in scratch log to demonstrate read audio w…
Browse files Browse the repository at this point in the history
…ave data and API usage (#363)
  • Loading branch information
nickyfantasy authored and daming-lu committed Apr 5, 2018
1 parent cfa6b02 commit 32ef4f9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
Binary file added demo/testing.wav
Binary file not shown.
27 changes: 27 additions & 0 deletions demo/vdl_create_scratch_log
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import os
import random

import numpy as np
import wave
from PIL import Image
from visualdl import ROOT, LogWriter
from visualdl.server.log import logger as log
Expand Down Expand Up @@ -91,6 +92,32 @@ with logw.mode("train") as logger:
image0.finish_sampling()



#create audio
with logw.mode("train") as logger:
audio = logger.audio("scratch/audio_1", 4) # randomly sample 4 audio one pass

CHUNK = 4096
f = wave.open('./testing.wav', "rb")
wavdata = []
chunk = f.readframes(CHUNK)

while chunk:
data = np.fromstring(chunk, dtype='uint8')
wavdata.extend(data)
chunk = f.readframes(CHUNK)

for pass_ in range(4):
audio.start_sampling()
for sample in range(10):
idx = audio.is_sample_taken()
if idx >= 0:
audio.set_sample(idx, 8000, wavdata)

audio.finish_sampling()



def download_graph_image():
'''
This is a scratch demo, it do not generate a ONNX proto, but just download an image
Expand Down

0 comments on commit 32ef4f9

Please sign in to comment.