Tbot-I 喇叭可以发出内置的声音,speaker 模块包含了相关方法和声音序号的常量定义,详情描述如下。

方法

  • speaker.play(number)
    播放内置的声音,参数number的取值范围是 0~174 ,为了更好的表达这些序号的意义,可以使用模块中定义的常量,例如 speaker.A0 表示音符A0、speaker.WIND 表示风声。
  • speaker.set_volume(number)
    设置音量大小,number取值范围 0~100,可以通过设置音量为 0 来设置静音,音量最大为 100。
  • speaker.check_busy()
    检查声音是否播放完毕,还在播放声音中返回 0 ,播放完毕返回 1 。

    定义的常量

    1. speaker.A0
    2. speaker.A1
    3. speaker.A2
    4. speaker.A3
    5. speaker.A4
    6. speaker.A5
    7. speaker.A6
    8. speaker.A_1
    9. speaker.AP0
    10. speaker.AP1
    11. speaker.AP3
    12. speaker.AP2
    13. speaker.AP4
    14. speaker.AP5
    15. speaker.AP6
    16. speaker.AP_1
    17. speaker.B0
    18. speaker.B1
    19. speaker.B2
    20. speaker.B3
    21. speaker.B4
    22. speaker.B5
    23. speaker.B6
    24. speaker.B_1
    25. speaker.C0
    26. speaker.C1
    27. speaker.C2
    28. speaker.C3
    29. speaker.C4
    30. speaker.C5
    31. speaker.C6
    32. speaker.C7
    33. speaker.CP0
    34. speaker.CP1
    35. speaker.CP2
    36. speaker.CP3
    37. speaker.CP4
    38. speaker.CP5
    39. speaker.CP6
    40. speaker.D0
    41. speaker.D1
    42. speaker.D2
    43. speaker.D3
    44. speaker.D4
    45. speaker.D5
    46. speaker.D6
    47. speaker.DP0
    48. speaker.DP1
    49. speaker.DP2
    50. speaker.DP3
    51. speaker.DP4
    52. speaker.DP5
    53. speaker.DP6
    54. speaker.E0
    55. speaker.E1
    56. speaker.E2
    57. speaker.E3
    58. speaker.E4
    59. speaker.E5
    60. speaker.E6
    61. speaker.F0
    62. speaker.F1
    63. speaker.F2
    64. speaker.F3
    65. speaker.F4
    66. speaker.F5
    67. speaker.F6
    68. speaker.FP0
    69. speaker.FP1
    70. speaker.FP2
    71. speaker.FP3
    72. speaker.FP4
    73. speaker.FP5
    74. speaker.FP6
    75. speaker.G0
    76. speaker.G1
    77. speaker.G2
    78. speaker.G3
    79. speaker.G4
    80. speaker.G5
    81. speaker.G6
    82. speaker.GP0
    83. speaker.GP1
    84. speaker.GP2
    85. speaker.GP3
    86. speaker.GP4
    87. speaker.GP5
    88. speaker.GP6
    89. speaker.AM
    90. speaker.BM
    91. speaker.C
    92. speaker.DM
    93. speaker.EM
    94. speaker.F
    95. speaker.G
    96. speaker.SEND
    97. speaker.WHINY
    98. speaker.RECEIVE
    99. speaker.GOODDD
    100. speaker.GOOD
    101. speaker.NOTHAPPY
    102. speaker.LETSGO
    103. speaker.OHMYGOD
    104. speaker.OHNO
    105. speaker.AMAZING
    106. speaker.VOC
    107. speaker.SOHAPPY
    108. speaker.AHHHH
    109. speaker.AIIII
    110. speaker.AOOOO
    111. speaker.HAHAHA
    112. speaker.HUM
    113. speaker.WHISTLE
    114. speaker.LALALA
    115. speaker.EMEMEM
    116. speaker.ROAR
    117. speaker.AWESOME
    118. speaker.SOHAPPY
    119. speaker.WAWAWA
    120. speaker.WAWAO
    121. speaker.WAO
    122. speaker.WUWUWU
    123. speaker.YEYEYE
    124. speaker.YOYOYO
    125. speaker.WHAT
    126. speaker.PLANE
    127. speaker.LANDING
    128. speaker.TRAIN
    129. speaker.BRAKE
    130. speaker.CAR
    131. speaker.TRUMPET
    132. speaker.SHIP
    133. speaker.TYRE
    134. speaker.MOTORBIKE
    135. speaker.SPORTCAR
    136. speaker.RACING
    137. speaker.JET
    138. speaker.TANK
    139. speaker.TRACTOR
    140. speaker.ENGINE
    141. speaker.COPTER
    142. speaker.ELEPHANT
    143. speaker.COCK
    144. speaker.DOG
    145. speaker.DINOSAUR
    146. speaker.WOLF
    147. speaker.TIGER
    148. speaker.CAT
    149. speaker.BIRD
    150. speaker.GOAT
    151. speaker.LION
    152. speaker.PIG
    153. speaker.CRACKER
    154. speaker.GLASS
    155. speaker.EAT
    156. speaker.HICCUP
    157. speaker.THUNDER
    158. speaker.CANNON
    159. speaker.WATER
    160. speaker.PHONE
    161. speaker.ALARM
    162. speaker.FART
    163. speaker.WIND
    164. speaker.SEA
    165. speaker.DRINKING
    166. speaker.GUN
    167. speaker.CUT
    168. speaker.DOORBELL
    169. speaker.KNOCK
    170. speaker.TOLL
    171. speaker.BOMB
    172. speaker.SHOOT
    173. speaker.CLEANER
    174. speaker.RAIN
    175. speaker.BULLET
    编程示范
    from thunbot import speaker
    import time
    speaker.play(speaker.A0)
    time.sleep_ms(10)
    while speaker.check_busy() == 0:
      print('.', end='')
      time.sleep_ms(200)
    print("end")
    

示例程序: speaker_test.py