How do string with quotes

13 visualizzazioni (ultimi 30 giorni)
Mario Martos
Mario Martos il 22 Mag 2016
Commentato: Image Analyst il 23 Mag 2016
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 Commenti
Mario Martos
Mario Martos il 23 Mag 2016
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 il 23 Mag 2016
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.

Accedi per commentare.

Risposte (1)

Image Analyst
Image Analyst il 22 Mag 2016
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 Commenti
Mario Martos
Mario Martos il 23 Mag 2016
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 il 23 Mag 2016
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.

Accedi per commentare.

Community Treasure Hunt

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

Start Hunting!

Translated by