I’m not sure, but there might be an add-on for that. Alternatively, if you know javascript, you can do that by using HTML audio
tag and manipulating the audio element with javascript. Here is an example:
Fields
-
audio_file
- audio file name
- make sure to add an underscore at the beginning of the file name so that it will not be deleted as an unused file during media check, and then put the file in the
collection.media
folder. - e.g.
_your_audio_file.mp3
-
start_pos
- set the start position (in seconds)
- can be empty
- e.g.
5
-
end_pos
- set the end position (in seconds)
- can be empty
- e.g.
10
Template
<audio id="my-audio" controls src="{{audio_file}}"></audio>
<script>
var startPos = parseInt('{{start_pos}}', 10);
startPos = startPos ? startPos : 0;
var endPos = parseInt('{{end_pos}}', 10);
var myAudio = document.querySelector('#my-audio');
myAudio.currentTime = startPos;
if (endPos) {
myAudio.addEventListener('timeupdate', () => {
if (myAudio.currentTime > endPos) {
myAudio.pause();
myAudio.currentTime = startPos;
}
});
} else {
myAudio.addEventListener('ended', () => {
myAudio.currentTime = startPos;
});
}
// To enable Autoplay:
// Requires Anki 2.1.36 beta3 or higher
// Enable "Automatically play audio" in the deck option
// Uncomment the next line
// myAudio.play();
</script>
Screenshot
Note
Anki 2.1.36 beta3 or higher is required to enable autoplay for <audio>
tag.
I tested this template on Anki 2.1.36 beta3 and AnkiDroid 2.14.0. I’m not sure if this works on AnkiMobile, since I don’t have an iOS device.