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?
#11
you can play the mp3 directly from the python script.
The easiest way to do this is with pygame mixer which is use like:
from pygame import mixer

def play_mp3(mp3filename):
    mixer.init()
    mixer.music.load(mp3filename)
    mixer.music.play()
Reply
#12
(Apr-04-2019, 09:09 PM)Larz60+ Wrote: you can play the mp3 directly from the python script.
The easiest way to do this is with pygame mixer which is use like:
from pygame import mixer

def play_mp3(mp3filename):
    mixer.init()
    mixer.music.load(mp3filename)
    mixer.music.play()

That's not what I'm trying to do.....

I need to change the output device to something other then my Windows default one.

Something like this: So that I can change the playback device

[Image: IMVXRvO.png]
Reply
#13
can be done with selenium, you've got a bit of a learning curve ahead of you, but there just happens to be a good tutorial on this forum, done by snippsat
Web-Scraping part-1
Web-scraping part-2 (Pages: 1 2 )
Reply
#14
(Apr-04-2019, 10:40 PM)Larz60+ Wrote: can be done with selenium, you've got a bit of a learning curve ahead of you, but there just happens to be a good tutorial on this forum, done by snippsat
Web-Scraping part-1
Web-scraping part-2 (Pages: 1 2 )

Man I'm not trying to web scrape. For f*** sakes.

....Am I missing something?? There's literally nothing in either part 1 or part 2 of those tutorials about sound/music/play/devices/ect. The only thing sound related on there is web scraping soundcloud.com which I'm not trying to do anything remotely close to that either.
Reply
#15
Is the image that you show your application?
And please refrain from vulgarity.
If it's not your app, the only way to automate changing the playback device (unless you have source code)
if to use some sort of browser automation like selenium or expect.
Reply
#16
(Apr-04-2019, 11:08 PM)Larz60+ Wrote: Is the image that you show your application?
And please refrain from vulgarity.
If it's not your app, the only way to automate changing the playback device (unless you have source code)
if to use some sort of browser automation like selenium or expect.

That is not my app. It is TeamSpeak, a voice communication program.

I don't want to automate changing the playback device. But I do want to change the playback device for my python script.

This is my script:

from gtts import gTTS
from pygame import *


t2s = gTTS(text="This text", lang='en').save("lastplayed.mp3")
mixer.init()
mixer.music.load("lastplayed.mp3")
mixer.music.play()

while mixer.music.get_busy():
    time.Clock().tick(100)
I want to make lastplayed.mp3 play in a DIFFERENT playback device. NOT my Windows DEFAULT one. A DIFFERENT one ("VB Audio Cable" which is a PLAYBACK DEVICE).
Reply
#17
this will go to your sound card.
to change output device, you need to change your sound card driver.
this is usually done automatically from headphone to speaker, but has nothing to do with python.
Perhaps you are not explaining properly.
Reply
#18
when you say "output through my mic" just what do you mean? do you mean to make a mic play sound like a speaker? do you mean to inject this sound where the mic sound is going? if the latter, where is the mic sound going?

and yes, please avoid vulgarity. my 11 year old grand-niece reads this forum sometimes.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#19
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
Reply
#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


Possibly Related Threads…
Thread Author Replies Views Last Post
  Play the next music in a list Pymax 0 1,181 Jul-28-2021, 07:27 PM
Last Post: Pymax
  how do i play an mp3 from a list gr3yali3n 3 2,074 Dec-01-2020, 08:50 AM
Last Post: Axel_Erfurt
  How to play against the computer Help_me_Please 4 3,990 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