当前位置:网站首页>There are applications related to web network request API in MATLAB (under update)
There are applications related to web network request API in MATLAB (under update)
2022-06-26 05:26:00 【Wake wrist】
Matlab There are about web Network request API Related applications of
1、webread Read the content
from RESTful Web service
data = webread(url)
from url designated Web The service reads the content and displays it in data Content returned in .
Returns an array of structures (struct array) And so on
If you want to store data , For example, save as Excel file
xlswrite %( Not recommended ) write in Microsoft Excel Spreadsheet files
It is not recommended to use xlswrite. Please switch to writetable、writematrix or writecell.
xlswrite(filename,A)
The matrix A write in Microsoft Excel Spreadsheet workbook filename The first worksheet in , From cell A1 Start writing .
writetable(T)
Will table T Write comma separated text files . The file name is the workspace variable name of the table , Additional extensions .txt.
writetable(T,filename)
Write with filename Specify the name and extension of the file .
# # First argument must be a table. struct2table(data)
writetable(___,Name,Value)
Through one or more Name,Value Other options specified for the group parameter write the table to a file , And can include any input parameter in the previous Syntax .
- data = webread(url) Get data from network request
- table = struct2table(data) Structure array is converted to table form
- writetable(table,filename) take table The table is written to the file
data = webread(url,QueryName1,QueryValue1,...,QueryNameN,QueryValueN)
According to one or more names - Value appends the query parameter to... In the way specified for the group parameter url. To put the query into the message body , Please use webwrite.Web Service definition query parameters .
2、webread Call Netease cloud API
First pass Matlab Read music , And realize the function of playing .
[y,Fs] = audioread(filepath)
From the name filename Read the data from the file in the , And return the sample data y And the sampling rate of the data Fs.
player = audioplayer(y,Fs)
Use sampling rate Fs Is the signal Y establish audioplayer object . This function returns the audio player object player.
play(player) Start playing songs
stop(player) Stop playing the song
pause(player) Pause the song
resume(player) Continue playing the song
Our method this time is to call Netease cloud music API Interface , Get music source file .
Interface : Process the processed interface : from https://api.vvhan.com/ Provide
Request example (mp3 Output ):
https://api.vvhan.com/api/rand.music?sort= Hot song list
Request example (JSON Output ):
https://api.vvhan.com/api/rand.music?type=json&sort= Hot song list
The specific process :
data = webread("https://api.vvhan.com/api/rand.music?type=json&sort= Hot song list ")
Get the data returned by the interface , With variable data preservation
data The data are as follows :
data.info The data are as follows :
name : The name of the song
auther : The singer name of the song
picUrl : The cover picture of the song Address
mp3url : Song source file MP3 Address
Simple test playback code :
data = webread("https://api.vvhan.com/api/rand.music?type=json&sort= Hot song list ");
music_infor = data.info
% Get the digital signal of audio y, And sampling frequency Fs
[y,Fs] = audioread(music_infor.mp3url);
% Use sampling rate Fs Is the signal Y establish audioplayer object . This function returns the audio player object player.
player = audioplayer(y,Fs);
% Start playing Audio player object player
play(player);
3、GUI Random music player
First , introduce player Object functions for
player Object functions for | player Introduction to the object function of |
---|---|
get | Inquire about audioplayer Property value of object |
isplaying | Inquire about audioplayer Property value of object |
pause | Pause playback or recording |
play | from audioplayer Object to play audio |
playblocking | Play audioplayer Object , Keep control until playback is complete |
resume | Resume playback or recording from a paused state |
set | Set up audioplayer Property value of object |
stop | Stop playing or recording |
Another introduction player Related object properties of
BitsPerSample - Number of sampling bits . Positive integer
CurrentSample - Currently playing samples . Positive integer
DeviceID - Audio device identifier . Integers
NumChannels - Number of audio channels 1 | 2
Running - Audio player status on | off
SampleRate - sampling frequency Numerical scalar
TotalSamples - Total length of audio data Integers
Tag - label Character vector
Type - Object class name 'audioplayer'
UserData - User defined data [] ( Default ) | Any data type
StartFcn - The function to execute at the beginning Character vector | String scalar | Function handle
StopFcn - The function to execute at the end Character vector | String scalar | Function handle
TimerFcn - The function to be repeated Character vector | String scalar | Function handle
TimerPeriod - Timer cycle 0.05 ( Default ) | Numerical scalar
Gui The interface design is as follows :
Get the code for the new song :
global player time
data = webread("https://api.vvhan.com/api/rand.music?type=json&sort= Hot song list ");
music_infor = data.info;
app.MusicName.Text = music_infor.name;
app.MusicSinger.Text = music_infor.auther;
% Get the digital signal of audio y, And sampling frequency Fs
[y,Fs] = audioread(music_infor.mp3url);
time = (length(y(:,1))/Fs);
Logo=imread(music_infor.picUrl);
app.MusicLogo.ImageSource = Logo;
app.MusicTime.Text = append('0:00',' / ',app.sec2ms(time));
% Use sampling rate Fs Is the signal Y establish audioplayer object . This function returns the audio player object player.
app.MusicHistory.Items(end+1) = {music_infor.name};
player = audioplayer(y,Fs);
play(player)
delete(timerfind)
function process(timer,event)
app.MusicProcess.Value = (player.CurrentSample / player.TotalSamples);
app.MusicTime.Text = append(app.sec2ms(time*(player.CurrentSample / player.TotalSamples)),' / ',app.sec2ms(time));
end
t = timer('StartDelay', 1,'Period', 1,'TasksToExecute', Inf,'ExecutionMode','fixedRate');
t.TimerFcn = @ process;
start(t)
边栏推荐
- Codeforces Round #800 (Div. 2)
- Two step processing of string regular matching to get JSON list
- 第九章 设置结构化日志记录(一)
- cartographer_ local_ trajectory_ builder_ 2d
- A beginner's entry is enough: develop mobile IM from zero
- LeetCode_ Binary search tree_ Simple_ 108. convert an ordered array to a binary search tree
- [greedy college] Figure neural network advanced training camp
- Baidu API map is not displayed in the middle, but in the upper left corner. What's the matter? Resolved!
- zencart新建的URL怎么重写伪静态
- Daily production training report (16)
猜你喜欢
uni-app吸顶固定样式
How to select the data transmission format of instant messaging application
Learn from small samples and run to the sea of stars
瀚高数据库自定义操作符‘!~~‘
Ad tutorial series | 4 - creating an integration library file
【ARM】在NUC977上搭建基于boa的嵌入式web服务器
[unity3d] rigid body component
Why does the mobile IM based on TCP still need to keep the heartbeat alive?
How does P2P technology reduce the bandwidth of live video by 75%?
9 common classes
随机推荐
uni-app吸顶固定样式
《财富自由之路》读书之一点体会
uniCloud云开发获取小程序用户openid
The beautiful scenery is natural, and the wonderful pen is obtained by chance -- how is the "wonderful pen" refined?
As promised: Mars, the mobile terminal IM network layer cross platform component library used by wechat, has been officially open source
11 IO frame
ECCV 2020 double champion team, take you to conquer target detection on the 7th
Replacing domestic image sources in openwrt for soft routing (take Alibaba cloud as an example)
Two step processing of string regular matching to get JSON list
Henkel database custom operator '~~‘
MySQL source code reading (II) login connection debugging
Setting pseudo static under fastadmin Apache
Uni app ceiling fixed style
vscode config
Technical problems to be faced in mobile terminal im development
The best Chinese open source class of vision transformer, ten hours of on-site coding to play with the popular model of Vit!
Second day of deep learning and tensorfow
AutowiredAnnotationBeanPostProcessor什么时候被实例化的?
cartographer_optimization_problem_2d
data = self._ data_ queue. get(timeout=timeout)