使用winsound模块播放声音

import winsound

import math

s = """3345 1233345 234 431 434 -612 12334567 +1+1345 23434+1+1
23434+2+2 +17+1+2+3+277+1 +175516 651132 345+17+1+2+3+2 77+1+175516
655+17+1
"""
freq = 440
i = 0
while i < len(s):
    c = s[i]
    if str.isspace(s[i]):
        i += 1
        continue
    print(c)
    if c == '+':
        c = int(s[i + 1]) - 6 + 7
        i += 2
    elif c == '-':
        c = int(s[i + 1]) - 7 - 6
        i += 2
    else:
        c = int(s[i]) - 6
        i += 1
    f = int(freq * math.pow(2, 1 / 7 * c))
    winsound.Beep(f, 500)

原文地址:https://www.cnblogs.com/weiyinfu/p/6338952.html