如何使用python 3控制树莓派的音量?

时间:2019-06-16 12:05:02

标签: raspberry-pi volume

我一直在网上查找有关使用python脚本控制树莓派(b +)音量的任何参考。我想出了this thread previously asked,但是python-alsaaudio不适用于python 3或在thonny python idle中说。 因此,我需要了解根据用户输入更改pi音量的任何正确方法。

1 个答案:

答案 0 :(得分:0)

另一种方法是通过命令行工具控制音量。 Alsa命令行有一个名为using Microsoft.Extensions.Caching.Memory; using SharpRepository.Repository; using SharpRepository.XmlRepository; using SharpRepository.Repository.Caching; using SharpRepository.EfRepository; public class MyEntity { public DateTime EventDateTime; public Dictionary<string, string> attributes = new Dictionary<string, string>(); } static void Main(string[] args) { MemoryCache memoryCache = new MemoryCache(new MemoryCacheOptions()); InMemoryCachingProvider inMemoryCachingProvider = new InMemoryCachingProvider(memoryCache); IRepository<MyEntity> myRepo = new XmlRepository<MyEntity>(@"C:\temp\MyLocalRepo", new StandardCachingStrategy<MyEntity>(inMemoryCachingProvider)); // When I am ready to further develop the data layer, I can swap the repo out for a different one //IRepository<MyEntity> myRepo = new EfRepository<MyEntity>(new System.Data.Entity.DbContext("myConnectionString")); // And my logic that interacts with the repository will still work myRepo.Add(new MyEntity { EventDateTime = new DateTime(2019, 06, 16), attributes = new Dictionary<string, string> { { "WithAttrbutes", "AndTheirValues" } } }); } 的工具:

amixer

现在,您可以创建一个运行上述命令的简单python脚本:

amixer sset Master 50%

您可以将import subprocess # a value between 0 and 100 volume = 50 command = ["amixer", "sset", "Master", "{}%".format(volume)] subprocess.Popen(command) 更改为其他声卡。您可以获取控件列表:

Master