I have used pygame a lot, but never used sound before. I have checked and the files are there by the right name, and I have used the right pathway, but I just get this error message:
Traceback (most recent call last):
File "C:\Users\Rajive\AppData\Local\Programs\Python\Python3.4.3\D C W.py", line 11, in module
door_opening = pygame.mixer.Sound('C:\Users\Rajive\Downloads\door_opening.m4a')
pygame.error: Unable to open file 'C:\Users\Rajive\Downloads\door_opening.m4a'
import random, time, pygame
time = time.clock()
pygame.init()
diff = 1
door_opening = pygame.mixer.Sound('C:\\Users\\Rajive\\Downloads\\door_opening.m4a')
door_closing = pygame.mixer.Sound('C:\\Users\\Rajive\\Downloads\\door_closing.m4a')
closet_opening = pygame.mixer.Sound('C:\\Users\\Rajive\\Downloads\\closet_opening.m4a')
closet_opening = pygame.mixer.Sound('C:\\Users\\Rajive\\Downloads\\closet_closing.m4a')
window_opening = pygame.mixer.Sound('C:\\Users\\Rajive\\Downloads\\window_opening.m4a')
window_opening = pygame.mixer.Sound('C:\\Users\\Rajive\\Downloads\\window_closing.m4a')
From pygame documentation:
The Sound can be loaded from an OGG audio file or from an uncompressed WAV.
Doesn't look like the .m4a codec is supported. Perhaps try converting your file first.
Related
I am trying to merge two files (.mp3 & .mp4) to a single .mp4
The videos and audio are located in the same folder as my main.py, and aren't corrupted
Here is the code that seems to create the error:
if (haveAudio):
infile1 = ffmpeg.input(title+"_video.mp4")
infile2 = ffmpeg.input(title+"_audio.mp3")
merged = ffmpeg.concat(infile1, infile2, v=1, a=1)
output = ffmpeg.output(merged[0], merged[1], title+".mp4")
I am getting an error on the last line:
Traceback (most recent call last):
File "C:\Users\...\projectName\main.py", line 67, in <module>
output = ffmpeg.output(merged[0], merged[1], title+".mp4")
File "C:\Users\...\Python\Python39\lib\site-packages\ffmpeg\nodes.py", line 70, in __getitem__
raise TypeError("Expected string index (e.g. 'a'); got {!r}".format(index))
TypeError: Expected string index (e.g. 'a'); got 0
My guess would be that an argument is missing when calling ffmpeg.output() but based on the documentation it seems correct.
I learnt from this tutorial: https://github.com/JNYH/pytube/blob/master/pytube_sample_code.ipynb
I used below 2 ways and they both worked for me:
audio = ffmpeg.input('audio.mp3')
video = ffmpeg.input('video.mp4')
ffmpeg.output(audio, video, 'my_file.mp4').run()
or
ffmpeg.concat(video, audio, v=1, a=1).output('my_file.mp4').run(overwrite_output=True)
So basically, I want to play two frequencies on top of each other. For example, 5000Hz and 10000Hz played simultaneously on top of each other at same time. So, I used winsound in Python and pygame library, but the sounds are playing one after another and I am getting this error:
Traceback (most recent call last):
File "xyz", line 14, in <module>
kk = mixer.Sound(Snd(5000, 1))
TypeError: Unrecognized argument (type NoneType)
I wrote this code:
import pygame
from pygame import mixer
import winsound
pygame.init()
def Snd(freq, dur):
return winsound.Beep(freq, 1000*dur)
ss = Snd(5000, 1)
s = Snd(10000, 1)
kk = mixer.Sound(ss)
kk.play(-1)
k = mixer.Sound(s)
k.play(-1)
I even tried this without the variables ss and s.
I am working on a python project to control vlc player - volume up/down, play/pause, rewind/forward and I have installed python2.7, vlc 3.0.8 32bit on windows 7. this is the code below which is to play the local mp4 file
import vlc
instance = vlc.Instance()
player = instance.media_player_new()
Media = instance.media_new('d:\1280.mp4')
Media.get_mrl()
player.set_media(Media)
player.play()
problem is the keywords - Instance and other functions are not getting highlighted except import and am getting the following error
Traceback (most recent call last):
File "C:\Python27\vlc3.py", line 4, in <module>
Media = instance.media_new('d:\1280.mp4')
File "C:\Python27\vlc.py", line 1916, in media_new
m._instance = self
AttributeError: 'NoneType' object has no attribute '_instance'
I am not able to understand please help me out
Use forward slashes instead of backward slashes.
Use:
Media = instance.media_new('d:/1280.mp4')
Instead of:
Media = instance.media_new('d:\1280.mp4')
im trying to display a video on a pygame surface using the pyglet library to import, play and then convert the frames into an image. I managed to battle my way through installing avbin but now I'm hitting a type error with my code
def cutscene(window_surface, filename):
player = pyglet.media.Player()
source = pyglet.media.load(filename)
player.queue(source)
player.play()
pygame.display.flip()
while True:
window_surface.fill(0)
player.dispatch_events()
tex = player.get_texture()
raw = tex.get_image_data().get_data('RGBA',tex.width*4)
raw = ctypes.string_at(ctypes.addressof(raw), ctypes.sizeof(raw))
img = pygame.image.frombuffer(raw, (tex.width, tex.height), 'RGBA')
window_surface.blit(img, (0,0))
pygame.display.flip()
when I run, i get the following error
Traceback (most recent call last):
File "dino_game.py", line 348, in <module>
main()
File "dino_game.py", line 45, in main
cutscene(window_surface, "Cutscenes/Cutscene1.mov")
File "dino_game.py", line 68, in cutscene
raw = tex.get_image_data().get_data('RGBA',tex.width*4)
AttributeError: 'NoneType' object has no attribute 'get_image_data'
Nothing that I do seems to solve it
EDIT: So after testing both this file and the sample files provided by pyglet, it seems that I get this error no matter what filetype I use, could this be an installation error with pyglet or AVbin?
Gave up trying to use pyglet and swapped to VLC where I just have to pass the window ID for the game and it does the rest for me
VLC script: https://wiki.videolan.org/Python_bindings/
Edit: Trying to get these libraries to work in python 3.3 was clearly the wrong approach, and my problem now is entirely different so I'll just re-ask it in a new question.
I want to be able to edit ID3 tags of mp3 files with python commands, for example something like setAlbumName("folderPath\song.mp3", "albumname"). So far I've tried Mutagen, PyID3, pytagger, eyeD3, and they all seem to be outdated because the installation fails due to syntax errors. I tried to fix it in eyeD3, but I hit a dead end: http://i41.tinypic.com/o6zklv.png (second screenshot from after I had fixed all the prints and "except Error, e" and so on).
I tried the same with Mutagen, but I ran into a wall there as well when replacing "raise KeyError, key" with "raise KeyError as key" didn't work.
I didn't even know what to make of this one (pytagger): http://i41.tinypic.com/29fz7mh.png
It seems to suggest that there's something wrong with my python installation? Not getting into that.
So, would anyone like to point me to an ID3 package that works, or have a go at fixing an outdated one?
(Also, I tried both "python setup.py install" and "setup.py install" and it seemed to make no difference. I'm on windows 8.)
Edit: From the screenshot below, plus the source code (mutagen with python 2.7.5)
from mutagen.mp3 import MP3
p = "E:\\Musik\\Aeon\\2005 Bleeding the False\\01 Cenobites - Copy.mp3"
audio = MP3(p)
audio["title"] = "An example"
audio.pprint()
audio.save()
_
Traceback (most recent call last):
File "id3tag.py", line 5, in <module>
audio.pprint()
File "C:\Python27\lib\site-packages\mutagen\__init__.py", line 138, in pprint
try: tags = self.tags.pprint()
File "C:\Python27\lib\site-packages\mutagen\id3.py", line 190, in pprint
frames = list(map(Frame.pprint, self.values()))
TypeError: unbound method pprint() must be called with Frame instance as first a
rgument (got str instance instead)
_
from mutagen.mp3 import MP3
p = "E:\\Musik\\Aeon\\2005 Bleeding the False\\01 Cenobites - Copy.mp3"
audio = MP3(p)
audio["title"] = "An example"
audio.save()
_
Traceback (most recent call last):
File "id3tag.py", line 7, in <module>
audio.save()
File "C:\Python27\lib\site-packages\mutagen\__init__.py", line 132, in save
return self.tags.save(filename, **kwargs)
File "C:\Python27\lib\site-packages\mutagen\id3.py", line 370, in save
framedata = [self.__save_frame(frame) for (key, frame) in frames]
File "C:\Python27\lib\site-packages\mutagen\id3.py", line 461, in __save_frame
framedata = frame._writeData()
AttributeError: 'str' object has no attribute '_writeData'
mutagen works great for me with Python 2.7.
examples:
https://code.google.com/p/mutagen/wiki/Tutorial
from mutagen.mp3 import MP3
audio = MP3("example.mp3")
audio["title"] = "An example"
audio.pprint()
audio.save()
p.s. please post code samples so people can help.. not links to screenshots.
p.p.s. it looks like you are trying to install Python2 libs into Python3.
Mutagen also has an EasyID3 tool, which handles simple tasks like changing the file's title:
from mutagen.easyid3 import EasyID3
f = EasyID3("file.mp3")
f["title"] = u"Some title"
f.save()
Works like a charm. But it has very restricted functionality.
See more examples at http://code.google.com/p/mutagen/wiki/Tutorial