Is there any solution for converting Wav to Ogg or MP3 by using pure PHP? Technically it's possible. But what about ready-made libraries?
Im talking about 1-7 sec wav.
Writing this in pure PHP will melt your brain for sure. That said, you can create a PHP extension wrapper around ffmpeg if you know enough C. That would probably be the most optimal.
Alternatively, you can just use exec()
unless you want to distribute your code and hate to have this as a (reasonable) dependency.
In both cases you would need to have a working ffmpeg library installed on the server.
Disclaimer
I didn't read this answer before writing my own :)