Hmm, no solution. Users can only select files from the photo album. If they can select audio files, where can they select audio files? ring? joke. recording? Native apps don’t have this permission.
If you must have this function, you can allow users to upload videos and then extract the audio in the background
--- update:
In fact, this is not very troublesome. The videos uploaded by users are not very large, and two or three servers can handle it. If this function is used sparingly, one server will suffice. Of course, you can also use a CDN to save trouble. Most of today’s CDNs provide media conversion processing, and you just need to pay a little money.
For Android machines, you can also use Java or Flash front-end to extract audio.
In addition, there is a second method that is to upload a video, but only the audio is played in the first part, so that the user cannot see the video content. However, in addition to the file that the user wants to download may be relatively large, it will also involve privacy.
So, if this function is dispensable to you, then give up this idea as soon as possible. If this function is necessary, it is recommended to use a CDN, or build your own server and use ffmpeg to specifically handle this.
This approach is actually very common in social applications of a slightly larger scale. Our company did something similar in 2009, where we wanted to play the speex audio recorded by client users on computer web pages and mobile web pages. I researched it for several days. , tried several solutions, and finally used the server to transfer. Twitter also converts GIFs uploaded by users into video files. In the modern web, converting a video on the server side is the same as processing images uploaded by users.
--- update:
Another solution is to allow users to record and upload audio in WeChat. WeChat's JS SDK has related interfaces. I just don’t know if it matches your product needs.
Hmm, no solution. Users can only select files from the photo album. If they can select audio files, where can they select audio files? ring? joke. recording? Native apps don’t have this permission.
If you must have this function, you can allow users to upload videos and then extract the audio in the background
--- update:
In fact, this is not very troublesome. The videos uploaded by users are not very large, and two or three servers can handle it. If this function is used sparingly, one server will suffice. Of course, you can also use a CDN to save trouble. Most of today’s CDNs provide media conversion processing, and you just need to pay a little money.
For Android machines, you can also use Java or Flash front-end to extract audio.
In addition, there is a second method that is to upload a video, but only the audio is played in the first part, so that the user cannot see the video content. However, in addition to the file that the user wants to download may be relatively large, it will also involve privacy.
So, if this function is dispensable to you, then give up this idea as soon as possible. If this function is necessary, it is recommended to use a CDN, or build your own server and use ffmpeg to specifically handle this.
This approach is actually very common in social applications of a slightly larger scale. Our company did something similar in 2009, where we wanted to play the speex audio recorded by client users on computer web pages and mobile web pages. I researched it for several days. , tried several solutions, and finally used the server to transfer. Twitter also converts GIFs uploaded by users into video files. In the modern web, converting a video on the server side is the same as processing images uploaded by users.
--- update:
Another solution is to allow users to record and upload audio in WeChat. WeChat's JS SDK has related interfaces. I just don’t know if it matches your product needs.
The answer is no, Safari does not have such an API
Some Android machines can do this, you can try it on iOS.
<input type="file" accept="audio/*">
accept is a standard HTML5 attribute.