当前位置:网站首页>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)
边栏推荐
- How to rewrite a pseudo static URL created by zenpart
- Introduction to GUI programming to game practice (II)
- cartographer_local_trajectory_builder_2d
- cartographer_ backend_ constraint
- AutowiredAnnotationBeanPostProcessor什么时候被实例化的?
- Positioning setting horizontal and vertical center (multiple methods)
- apktool 工具使用文档
- 数据存储:MySQL之InnoDB与MyISAM的区别
- tensorlow:cifar100_ train
- Official image acceleration
猜你喜欢

How does P2P technology reduce the bandwidth of live video by 75%?
![[unity3d] rigid body component](/img/57/344aae65e4ac6a7d44b235584f95d1.png)
[unity3d] rigid body component

Redis usage and memory optimization

百度API地图的标注不是居中显示,而是显示在左上角是怎么回事?已解决!

cartographer_pose_graph_2d

Could not get unknown property ‘*‘ for SigningConfig container of type org. gradle. api. internal

创建 SSH 秘钥对 配置步骤
![[arm] build boa based embedded web server on nuc977](/img/fb/7dc1898e35ed78b417770216b05286.png)
[arm] build boa based embedded web server on nuc977

The parameter field of the callback address of the payment interface is "notify_url", and an error occurs after encoding and decoding the signed special character URL (,,,,,)

Serious hazard warning! Log4j execution vulnerability is exposed!
随机推荐
慢慢学JVM之缓存行和伪共享
Classic theory: detailed explanation of three handshakes and four waves of TCP protocol
Douban top250
小小面试题之GET和POST的区别
[red team] what preparations should be made to join the red team?
百度API地图的标注不是居中显示,而是显示在左上角是怎么回事?已解决!
localStorage浏览器本地储存,解决游客不登录的情况下限制提交表单次数。
SOFA Weekly | 开源人—于雨、本周 QA、本周 Contributor
Second day of deep learning and tensorfow
cartographer_ fast_ correlative_ scan_ matcher_ 2D branch and bound rough matching
程序人生
[upsampling method opencv interpolation]
FastAdmin Apache下设置伪静态
Daily production training report (17)
Ad tutorial series | 4 - creating an integration library file
Redis discovery bloom filter
Apktool tool usage document
Redis installation on Linux
ZigBee learning in simple terms lesson 3 external interruption
How to select the data transmission format of instant messaging application