How do string with quotes

조회 수: 13 (최근 30일)
Mario Martos
Mario Martos 2016년 5월 22일
댓글: Image Analyst 2016년 5월 23일
Hello, I wanted to ask two questions when creating a character string to process a function in matlab. I want to do the following (which is to extract an audio wav youtube URL); where I created and saved in the directory wav youtube with the id of the shape e4d0LOuP4Uw.wav
system ( 'youtube-dl -x --audio-format wav --id https://www.youtube.com/watch?v=e4d0LOuP4Uw');
Well but that string the address is an input parameter that reads the URL of youtube after performing the above command is:
youtube_id = https: //www.youtube.com/watch?v = e4d0LOuP4Uw
then I want you, I read that parameter youtube_id but in quotation marks and do not know how to do ...
system ( "sudo youtube-dl -x --audio-format wav --id 'youtube_id);
How do I enter the input parameter enters quotes?
The second question is, how can I upload or just call that file is saved me or I believe in the working directory or folder e4d0L0uP4Uw.wav for use later in the function?
Thanks in advanced!
  댓글 수: 3
Mario Martos
Mario Martos 2016년 5월 23일
Hello, I have a function in matlab for example :
function [ ] = principal ( youtube_url ) ;
To which I pass a YouTube URL ; and I want you in that role where I have the following line:
command = " youtube- dl -x --audio -format wav --id ' youtube_url ;
system (command ) ;
where youtube- dl is a program that I call from matlab , but the only thing that interests me is to hold my string to process that line, but if it is not in quotation marks the entry does not work for me , and I want to know how to step that youtube_url parameter to be for example any url that goal is in quotes because that command I extract the wav that video.
On the other hand , I get thereby extract a .wav in the work file folder , and then I want to call or use just the extracted wav but how could call it or use it in that function to wav generated ? Because for each url that you enter I will extract the corresponding wav that video.
Mario Martos
Mario Martos 2016년 5월 23일
The function would look like or what you want to do:
function [] = principal (youtube_url); % If you do not introduce quotes I think I would not work ...
command = [ 'youtube-dl -x YouTube- --audio -format --id wav' youtube_url];
system (command);
audio_wav = audioread (fullfile (pwd [youtube_id '.wav'])); % Where here I want to read the extracted wav that has the name of the ID entered Youtube URL for later use or processing.
or,
[Y, FS, NBITS] = audioread (youtube_id '.wav')% I do not know what to call that .wav
New = resample (Y, 441.480);
wavwrite (New, 44100, name '.wav');
An example of how it should be or be for an example of url:
function [] = principal ( 'https://www.youtube.com/watch?v=e4d0LOuP4Uw');
command = [ 'youtube-dl -x YouTube- --audio -format --id https://www.youtube.com/watch?v=e4d0LOuP4Uw wav'];
system (command);
[Y, FS, NBITS] = audioread ( 'e4d0LOuP4Uw.wav');
or,
audio_wav = audioread (fullfile (pwd [ 'e4d0LOuP4Uw.wav'])); % I do not know what to call that I have drawn wav.
New = resample (Y, 441,480);
wavwrite (New, 44100, 'name .wav');
I hope I explained well, thank you very much.

댓글을 달려면 로그인하십시오.

답변 (1개)

Image Analyst
Image Analyst 2016년 5월 22일
Perhaps this will help:
stringWithDoubleQuote = 'abc"def'
stringWithSingleQuote = 'abc''def'
singleQuote = 39; % ASCII for single quote
stringWithSingleQuote = sprintf('abc%cdef', singleQuote)
In command window:
stringWithDoubleQuote =
abc"def
stringWithSingleQuote =
abc'def
stringWithSingleQuote =
abc'def
  댓글 수: 3
Mario Martos
Mario Martos 2016년 5월 23일
The function would look like or what you want to do:
function [] = principal (youtube_url); % If you do not introduce quotes I think I would not work ...
command = [ 'youtube-dl -x YouTube- --audio -format --id wav' youtube_url];
system (command);
audio_wav = audioread (fullfile (pwd [youtube_id '.wav'])); % Where here I want to read the extracted wav that has the name of the ID entered Youtube URL for later use or processing.
or,
[Y, FS, NBITS] = audioread (youtube_id '.wav')% I do not know what to call that .wav
New = resample (Y, 441.480);
wavwrite (New, 44100, name '.wav');
An example of how it should be or be for an example of url:
function [] = principal ( 'https://www.youtube.com/watch?v=e4d0LOuP4Uw');
command = [ 'youtube-dl -x YouTube- --audio -format --id https://www.youtube.com/watch?v=e4d0LOuP4Uw wav'];
system (command);
[Y, FS, NBITS] = audioread ( 'e4d0LOuP4Uw.wav');
or,
audio_wav = audioread (fullfile (pwd [ 'e4d0LOuP4Uw.wav'])); % I do not know what to call that I have drawn wav.
New = resample (Y, 441,480);
wavwrite (New, 44100, 'name .wav');
I hope I explained well, thank you very much
Image Analyst
Image Analyst 2016년 5월 23일
You can do this:
command = sprintf('youtube-dl -x YouTube- --audio -format --id "%s"', youtube_url);
This makes up the command line string with the URL you passed in enclosed in double quotes, which is how I think the system() command wants it.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Audio and Video Data에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by