简体   繁体   English

使用谷歌驱动器中的文件而不是在 colab 中上传

[英]Using files from google drive rather than uploading in colab

I am following我正在关注

https://colab.research.google.com/drive/1tzUmbS4lFP3xr6khSojg2vFCAx6xfW5r#scrollTo=EfkTM9TjUCRx https://colab.research.google.com/drive/1tzUmbS4lFP3xr6khSojg2vFCAx6xfW5r#scrollTo=EfkTM9TjUCRx

Real Time Voice Cloning.实时语音克隆。

I need help with Second section of this notebook where we have to record or upload file.我需要有关此笔记本第二部分的帮助,我们必须在其中记录或上传文件。 I have multiple files in my google drive which i have mounted in colab and want to use them rather than uploading same from pc ( which is very slow )我的谷歌驱动器中有多个文件,我已经安装在 colab 中并且想要使用它们而不是从 pc 上传相同的文件(这很慢)

can anyone help me with solution for this code block?谁能帮我解决这个代码块? like using wav/mp3 from our drive rather than uploading them via upload file button?喜欢使用我们驱动器中的 wav/mp3 而不是通过上传文件按钮上传它们?

want to change this code to use local files rather than uploading from pc:想要更改此代码以使用本地文件而不是从 pc 上传:

#@title Run this cell to Record or Upload Audio
#@markdown * Either record audio from microphone or upload audio from file (.mp3 or .wav) 

SAMPLE_RATE = 22050
record_or_upload = "Upload (.mp3 or .wav)" #@param ["Record", "Upload (.mp3 or .wav)"]
record_seconds =   13111#@param {type:"number", min:219, max:10, step:3}

embedding = None
def _compute_embedding(audio):
  display(Audio(audio, rate=SAMPLE_RATE, autoplay=True))
  global embedding
  embedding = None
  embedding = encoder.embed_utterance(encoder.preprocess_wav(audio, SAMPLE_RATE))
def _record_audio(b):
  clear_output()
  audio = record_audio(record_seconds, sample_rate=SAMPLE_RATE)
  _compute_embedding(audio)
def _upload_audio(b):
  clear_output()
  audio = upload_audio(sample_rate=SAMPLE_RATE)
  _compute_embedding(audio)

if record_or_upload == "Record":
  button = widgets.Button(description="Record Your Voice")
  button.on_click(_record_audio)
  display(button)
else:
  #button = widgets.Button(description="Upload Voice File")
  #button.on_click(_upload_audio)
  _upload_audio("")

I have done:我已经做好了:

from google.colab import drive
drive.mount('/content/drive/')

then然后

%cp -av "/content/drive/MyDrive/test.wav" "/content/"

test.wav is copied now I want to use that directly rather than upload or record. test.wav现在被复制了,我想直接使用它而不是上传或记录。

If I understood the problem correctly, you want to read the file directly from google Drive.如果我正确理解了这个问题,你想直接从谷歌云端硬盘读取文件。 Steps:脚步:

Mount google drive:挂载谷歌驱动器:

from google.colab import drive
drive.mount('/content/gdrive/')

After that cd to the directory where you have the files:之后cd到您拥有文件的目录:

curr_dir =  "/content/gdrive/My Drive/path/to/files/"
%cd "$curr_dir"

My Drive is the home directory of Google Drive (where you land when you open google drive).我的云端硬盘是 Google 云端硬盘的主目录(当您打开 Google 云端硬盘时您登陆的位置)。 Then you can read files as if reading from a local drive.然后您可以像从本地驱动器读取文件一样读取文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM