Is there a way to imitate sound input with python? - python

I wanted to make a program that would pass some sound data to the system's microphone, imitating person's speech. Originally I wanted it to "talk" in a discord voice chat to other people, but I couldn't find any way to do so.
I tried libraries like SoundCard and PyAudio, but they seem to only have functions to either get the mic input from the user, or to output sound via speakers. However, I want it to simulate microphone input.
So, is there any way to do this with python (or any other language)?
Thanks in advance.

Related

Play sound through Microphone Windows 10

I wanted to make a soundboard that works in voice calls. I tried a few methods, like the play sound module but they don't do what I want them to do. Would I need a lower level library to accomplish something like this and if so what should I be looking for?

How to listen to audio output by application

Background
I'm working on a music player, and want any sort of audio visualizer to be part of it. I've already made a previous post specifically targeting python-vlc, but I guess not too many people know about it. Here is the post in question: How to get audio samples from python-VLC
What I need
I need a way to listen to audio output, preferably by application although it is not completely necessary. It must be a python module.
What I found
A bunch of tutorials regarding audio input from the microphone, which is NOT what I need
Two swhardware.com tutorials with audio visualizers
https://swharden.com/blog/2016-07-19-realtime-audio-visualization-in-python/
Another one from 2013 but I can't find the link
PyAudio tutorials also using the microphone
Listening audio output with python
terminatorX on Linux; it uses the microphone
squishyball on Linux; it doesn't support all audio files
livefft; uses pyqt4 so I couldn't even test it
Alternatives
Any python module or linux terminal that can provide a list of audio samples from any audio file. Similar to pydub.AudioSegement.get_array_of_samples()
What I don't need
More suggestions to use pydub's get_array_of_samples()
Pydub doesn't read the audio file correctly and quickly gets out of sync from already playing audio
More tutorials of how to get audio from the microphone
Answers on how to strip audio from a video file with ffmpeg

Converting speech to text in real time using Python

I'm currently trying to create a program that will print what is being said through a microphone input into console as it is being said, rather in just one big block after the user is finished saying whatever they want to say. How would I extend the SpeechRecognition/PyAudio Modules in order to achieve this. I'm thinking it may involve being able to detect when someone has finished saying a word and then looping back around to the voice detection, but I wouldnt be sure how to implement that.
This is just the basic example I'm going off of in order to print the text after the user is finished speaking:
microphone = sr.Microphone(device_index=0)
r = sr.Recognizer()
with microphone as source:
audio = r.listen(source)
print(r.recognize_google(audio))
Thanks :)

Python: play sound as input

Is it possible to play a wav/mp3/... file, so that the system thinks, its a microphone that plays the sound?
For example, I have this list of sounds:
1.wav
2.wav
3.wav
Now I have a terminal, that lets me choose one of this sounds. Is it possible to let Python act like a microphone?

Get current audio frequency amplitudes or spectrum in Linux Python

so currently I'm trying to make a Python script which reads the ALSA Mixer's output (or rather the general audio output) for the volumes/amplitudes of the current playing audio frequencies to trigger the GPIO ports on my Raspberry Pi, so I can effectively make an EQ out of LEDs responding to the current audio output. I want to create a real-time analysis (which is not bounded to the ALSA Mixer, whatever works, works), so I can stream my music from my iPhone via Airplay to the Raspberry Pi or watch a YouTube video and the LED-EQ is, well, doing what it's supposed to do.
My problem is that I coudn't found any library or function in python on the Internet, which let's me get the current audio output or rather the frequency amplitudes. Does anybody have an idea of how to make this thing going?
P.S.: I tried Lightshowpi but I couldn't figure out how to use Shairport-sync with it, so if anyone has an answer to that, let me know it. :)
Edit:
If there's a way to get the wave form from the e.g. the last 8 Bytes of the audio stream I may do a fourier transformation (could a fourier transformation really work in a real-time environment, because of the heavy maths load on the CPU?)

Categories

Resources