当前位置:网站首页>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)
- Protocol selection of mobile IM system: UDP or TCP?
- 2021年OWASP-TOP10
- data = self._ data_ queue. get(timeout=timeout)
- 【上采样方式-OpenCV插值】
- The best Chinese open source class of vision transformer, ten hours of on-site coding to play with the popular model of Vit!
- 【MYSQL】MySQL 百万级数据量分页查询方法及其优化
- cartographer_backend_constraint
- Mise en file d'attente des messages en utilisant jedis Listening redis stream
- ZigBee learning in simple terms Lecture 1
猜你喜欢

Command line interface of alluxio

慢慢学JVM之缓存行和伪共享

Replacing domestic image sources in openwrt for soft routing (take Alibaba cloud as an example)

Baidu API map is not displayed in the middle, but in the upper left corner. What's the matter? Resolved!

cartographer_pose_graph_2d

Second day of deep learning and tensorfow

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

The best Chinese open source class of vision transformer, ten hours of on-site coding to play with the popular model of Vit!
The wechat team disclosed that the wechat interface is stuck with a super bug "15..." The context of

红队得分方法统计
随机推荐
How to ensure the efficiency and real-time of pushing large-scale group messages in mobile IM?
MySQL source code reading (II) login connection debugging
Gd32f3x0 official PWM drive has a small positive bandwidth (inaccurate timing)
June 3 is a happy day
Daily production training report (17)
ZigBee explain in simple terms lesson 2 hardware related and IO operation
Internship May 29, 2019
程序人生
Implementation of IM message delivery guarantee mechanism (II): ensure reliable delivery of offline messages
11 IO frame
uniCloud云开发获取小程序用户openid
apktool 工具使用文档
Leetcode513. Find the value in the lower left corner of the tree
cartographer_backend_constraint
Red team scoring method statistics
skimage. morphology. medial_ axis
Serious hazard warning! Log4j execution vulnerability is exposed!
ZigBee learning in simple terms Lecture 1
Pytorch forecast house price
Positioning setting horizontal and vertical center (multiple methods)