element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Community Hub
Community Hub
Member's Forum python code for raspberry pi
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Leaderboard
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Community Hub to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • Replies 4 replies
  • Subscribers 531 subscribers
  • Views 912 views
  • Users 0 members are here
  • python programming
  • audio
  • python 3.7
  • raspberrypi
  • python code
  • software
Related

python code for raspberry pi

fskrzycki
fskrzycki over 1 year ago

# Music starts after sudo reboot, but not at initial power up.
# When audio file plays. It plays at 2x speed.
# I tried using pydub to correct the speed, but I think it conflicts with my audio card because nothing plays when I add the code. This mp3 file does play at normal speed when selected with a regular audio player

please suggest a solution

Start-up-music-for-Raspberry-Pi
#music plays when headless starts up.
# This is the location of my service file ( /etc/systemd/system/opening_audio.service)
# opening_audio.service
[Unit]
Description=plays Let It Rip when powered on

[Service]

ExecStart=/usr/bin/python /home/Bay/Bookshelf/play_mp3.py
Restart=always
User=Bay

[Install]
WantedBy=multi-user.target

#This is the Program ( Play_mp3.py )

import pygame
import time

pygame.mixer.init()
pygame.mixer.music.load("/home/Bay/Music/letitrip.mp3")
pygame.mixer.music.set_volume(0.5)
time.sleep(3)
pygame.mixer.music.play()
pygame.time.delay(9000)
pygame.mixer.music.stop()
pygame.quit()

  • Sign in to reply
  • Cancel

Top Replies

  • shabaz
    shabaz over 1 year ago +1
    In case you don't get a better answer: it could be any number of things, there's some self-troubleshooting that will be needed. Without the troubleshooting, the "hack" way would be to record an MP3 file…
  • Gough Lui
    Gough Lui over 1 year ago +1
    Perhaps you might want to check the encoding parameters of your MP3 file in case it is the cause. I'd recommend any constant bit rate at 48kHz Stereo as that tends to avoid issues.
Parents
  • Gough Lui
    Gough Lui over 1 year ago

    Perhaps you might want to check the encoding parameters of your MP3 file in case it is the cause.

    I'd recommend any constant bit rate at 48kHz Stereo as that tends to avoid issues.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Cancel
  • fskrzycki
    fskrzycki over 1 year ago in reply to Gough Lui

    I should be able to change encoding parameters with Audacity. I did use it to convert the file from a wav to mp3.  I dont understand running it manually. I want it to start as automatically with the Pi receives power. 

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • shabaz
    shabaz over 1 year ago in reply to fskrzycki

    "I dont understand running it manually. I want it to start as automatically with the Pi receives power. "

    I presume that's a reply to me?

    I understand that you wished to run it automatically, this was obvious. It's part of the process of troubleshooting to narrow down the problem. The suggestions listed above are things intended to get closer to understanding the problem.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
Reply
  • shabaz
    shabaz over 1 year ago in reply to fskrzycki

    "I dont understand running it manually. I want it to start as automatically with the Pi receives power. "

    I presume that's a reply to me?

    I understand that you wished to run it automatically, this was obvious. It's part of the process of troubleshooting to narrow down the problem. The suggestions listed above are things intended to get closer to understanding the problem.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
Children
No Data
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube