Python Forum
How can I send a .mp3 to play through my mic?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How can I send a .mp3 to play through my mic?
#20
from pygame._sdl2 import get_num_audio_devices, get_audio_device_name
from pygame import mixer

mixer.init()
# a list of alternative >OUTPUT< devices
print(list(get_audio_device_name(x, 0).decode() for x in range(get_num_audio_devices(0))))

#then....

mixer.init(devicename='one of the device names from above')
mixer.music.load("lastplayed.mp3")
mixer.music.play()
I'm still looking for how to pipe output to an input (so it can be picked up by zoom, say) it seems OBS can do this so it might be a case of working out how.


(Apr-05-2019, 06:09 PM)ejected Wrote: I want the text to speech to go through my mic so that people who are in a voice channel with me will hear the text to speech.

I don't know how else to explain it... I really don't. I don't mean to sound rude or mean or condescending or whatever I understand you guys are just trying to help me, but maybe if you guys aren't native Americans translate it to your native language? Again don't mean to sound like a poopy face or whatever, but maybe that will help?

Here are some alternative explanations of what I want to do/worded a bit differently:

- play a .mp3 through my microphone (on Discord/TeamSpeak/Skype/other voice comm programs) instead of speakers.
- play a .mp3 through my VB Audio Cable (which is a different playback device I have, OTHER THEN my default one. [see this screenshot: https://i.imgur.com/R5tUECr.png)
- play .mp3 music through my microphone (on Discord/TeamSpeak/Skype/ect)
- play .mp3 to my default RECORDING DEVICE. INSTEAD OF PLAYBACK DEVICE. [ https://imgur.com/a/Phe7zE1 ]
- play .mp3 to a SPECIFIC PLAYBACK DEVICE. NOT MY DEFAULT ONE. (while not changing it to default. For example, you know how you can change your recording device on Skype/TeamSpeak/Discord ect? Like that.) [Example of another program that does this: https://i.imgur.com/IMVXRvO.png - See how you can choose a specific playback device? This is what I want to do. I want to choose a specific playback device to use instead of my default one.]

- Change the playback output device of this voice1.mp3 TO A SPECIFIC PLAYBACK DEVICE. NOT MY DEFAULT WINDOWS ONE:
from gtts import gTTS

 
t2s = gTTS(text="Hello this is the text to play", lang='en')
t2s.save("voice1.mp3")
to a device other then my default one. (again to this: https://i.imgur.com/R5tUECr.png)

- Make this play voice1.mp3 THROUGH MY RECORDING DEVICE (microphone) INSTEAD OF MY PLAYBACK DEVICE (to one of THESE: https://i.imgur.com/AO4Vx5p.png)

from gtts import gTTs
 
t2s = gTTS(text="Hello this is the text to play", lang='en')
t2s.save("voice1.mp3")
Any ONE of those methods in the explanations above is enough. I don't need all of them. Just one should work.


(Apr-05-2019, 04:35 AM)Skaperen Wrote: to inject this sound where the mic sound is going? if the latter, where is the mic sound going?

Yes. This is what I mean. The mic sound is going to any voice recording software/program/game. (For example: Skype call. ANY program that records the mic)


So I managed to get this to (maybe) work but now I'm getting this error. How do I get pygame to use that audio driver?

from gtts import gTTS
import os


t2s = gTTS(text="This text", lang='en').save("lastplayed.mp3")

from pygame import *
os.putenv('SDL_AUDIODRIVER', 'vbaudiovacwdm')
mixer.init()
mixer.music.load("lastplayed.mp3")
mixer.music.play()

while mixer.music.get_busy():
    time.Clock().tick(100)
C:\Users\Mario\PycharmProjects\N1\venv\Scripts\python.exe C:/Users/Mario/PycharmProjects/N1/venv/new.py
pygame 1.9.5
Traceback (most recent call last):
Hello from the pygame community. https://www.pygame.org/contribute.html
  File "C:/Users/Mario/PycharmProjects/N1/venv/new.py", line 9, in <module>
    mixer.init()
pygame.error: No available audio device

Process finished with exit code 1
Larz60+ write Oct-16-2021, 07:02 PM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Fixed for you this time. Please use bbcode tags on future posts
Reply


Messages In This Thread
Is this possible to make in Python? - by ejected - Apr-04-2019, 01:23 AM
RE: How can I send a .mp3 to play through my mic? - by jamesetaylor - Oct-16-2021, 05:19 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Play the next music in a list Pymax 0 1,253 Jul-28-2021, 07:27 PM
Last Post: Pymax
  how do i play an mp3 from a list gr3yali3n 3 2,243 Dec-01-2020, 08:50 AM
Last Post: Axel_Erfurt
  How to play against the computer Help_me_Please 4 4,214 Aug-29-2019, 03:37 PM
Last Post: ThomasL

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020