Created
June 1, 2022 06:33
-
-
Save skyline75489/3f39c15cd9b0837afc4ea5d049acc4b8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import os | |
import traceback | |
import torch | |
import torchaudio | |
import requests | |
import torch.backends._nnapi.prepare | |
import torch.utils.bundled_inputs | |
import torch.utils.mobile_optimizer | |
import numpy as np | |
from onnx import numpy_helper, TensorProto | |
SPEECH_URL = "https://pytorch-tutorial-assets.s3.amazonaws.com/VOiCES_devkit/source-16k/train/sp0307/Lab41-SRI-VOiCES-src-sp0307-ch127535-sg0042.wav" # noqa: E501 | |
SPEECH_FILE = "_assets/speech.wav" | |
if not os.path.exists(SPEECH_FILE): | |
os.makedirs("_assets", exist_ok=True) | |
with open(SPEECH_FILE, "wb") as file: | |
file.write(requests.get(SPEECH_URL).content) | |
waveform, sample_rate = torchaudio.load(SPEECH_FILE) | |
input_ids_tensor = numpy_helper.from_array(waveform.numpy(), "input_ids") | |
f = open('audio_waveform','wb') | |
f.write(input_ids_tensor.SerializeToString()) | |
f.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment