f4a6c738beabc312a848804e5c4d4f384919f026,tensorboardX/summary.py,,audio,#Any#Any#Any#,394

Before Change



def audio(tag, tensor, sample_rate=44100):
    tensor = make_np(tensor)
    tensor = tensor.squeeze()
    if abs(tensor).max() > 1:
        print("warning: audio amplitude out of range, auto clipped.")
        tensor = tensor.clip(-1, 1)
    assert(tensor.ndim == 1), "input tensor should be 1 dimensional."

    tensor_list = [int(32767.0 * x) for x in tensor]
    import io
    import wave
    import struct
    fio = io.BytesIO()
    Wave_write = wave.open(fio, "wb")
    Wave_write.setnchannels(1)
    Wave_write.setsampwidth(2)
    Wave_write.setframerate(sample_rate)
    tensor_enc = b""
    tensor_enc += struct.pack("<" + "h" * len(tensor_list), *tensor_list)

    Wave_write.writeframes(tensor_enc)
    Wave_write.close()
    audio_string = fio.getvalue()

After Change


        print("warning: audio amplitude out of range, auto clipped.")
        tensor = tensor.clip(-1, 1)
    if tensor.ndim == 1:  // old API, which expects single channel audio
        tensor = np.expand_dims(tensor, axis=1)

    assert(tensor.ndim == 2), "Input tensor should be 2 dimensional."
    length_frames, num_channels = tensor.shape
    assert num_channels == 1 or num_channels == 2, "The second dimension should be 1 or 2."

    with io.BytesIO() as fio:
        soundfile.write(fio, tensor, samplerate=sample_rate, format="wav")
        audio_string = fio.getvalue()

    audio = Summary.Audio(sample_rate=sample_rate,
                          num_channels=num_channels,
Italian Trulli
In pattern: SUPERPATTERN

Frequency: 3

Non-data size: 7

Instances


Project Name: lanpa/tensorboardX
Commit Name: f4a6c738beabc312a848804e5c4d4f384919f026
Time: 2020-06-29
Author: prafullasd@gmail.com
File Name: tensorboardX/summary.py
Class Name:
Method Name: audio


Project Name: hanxiao/bert-as-service
Commit Name: d97188ee62bc0627235578485c5df7d3245fa1ed
Time: 2018-12-02
Author: hanhxiao@tencent.com
File Name: example6.py
Class Name:
Method Name:


Project Name: bokeh/bokeh
Commit Name: beb173d604c9f975b7eed1c6e8e1152a3d4aab12
Time: 2017-04-25
Author: lcanavan@continuum.io
File Name: bokeh/io.py
Class Name:
Method Name: export